Skip to content

Commit

Permalink
Process nested schema reference
Browse files Browse the repository at this point in the history
  • Loading branch information
McSym28 committed Jun 5, 2024
1 parent 571e158 commit 527cac2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/open_api/processor/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ defmodule OpenAPI.Processor.Type do
# Schema references
#
def from_schema(state, {:ref, full_path}) do
schema_spec = Map.fetch!(state.schema_specs_by_path, full_path)
from_schema(state, schema_spec)
with {_absolute_file, ["components", "schemas", schema_name]} <- full_path,
%State{spec: %Spec{components: %Spec.Components{schemas: schemas}}} = state,
{:ref, _} = schema_ref <- Map.get(schemas, schema_name) do
from_schema(state, schema_ref)
else
_ ->
schema_spec = Map.fetch!(state.schema_specs_by_path, full_path)
from_schema(state, schema_spec)
end
end

# Primitives
Expand Down
29 changes: 29 additions & 0 deletions test/fixture/schema-reference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: "3.1.0"
info:
title: Schema Reference Spec
version: 1
paths:
"/example_reference":
get:
description: "Example reference endpoint"
operationId: example_reference
summary: "Example reference endpoint"
responses:
"200":
description: "Success"
content:
"application/json":
schema:
"$ref": "#/components/schemas/user_reference"
components:
schemas:
user:
type: object
properties:
id:
type: integer
required:
- id
- team
user_reference:
"$ref": "#/components/schemas/user"

0 comments on commit 527cac2

Please sign in to comment.