diff --git a/lib/open_api_spex/open_api.ex b/lib/open_api_spex/open_api.ex index 8e993129..8e8ee1bb 100644 --- a/lib/open_api_spex/open_api.ex +++ b/lib/open_api_spex/open_api.ex @@ -96,11 +96,15 @@ defmodule OpenApiSpex.OpenApi do defmodule YmlrEncoder do @moduledoc false - def encode(api_spec = %{}, _options) do + def encode(api_spec = %OpenApi{}, _options) do api_spec |> OpenApi.to_map() |> Ymlr.document() end + + def encode(api_spec = %{}, _options) do + Ymlr.document(api_spec) + end end @yaml_encoder YmlrEncoder diff --git a/test/support/tasks/openapi.json b/test/support/tasks/openapi.json index 73f6fdb3..479f2e1c 100644 --- a/test/support/tasks/openapi.json +++ b/test/support/tasks/openapi.json @@ -1,4 +1,33 @@ { + "components": { + "schemas": { + "Person": { + "example": { + "first_name": "John", + "last_name": "Doe", + "nickname": null + }, + "properties": { + "first_name": { + "type": "string" + }, + "last_name": { + "type": "string" + }, + "nickname": { + "nullable": true, + "type": "string" + } + }, + "required": [ + "first_name", + "last_name", + "nickname" + ], + "type": "object" + } + } + }, "info": { "title": "Test spec", "version": "1.0" diff --git a/test/support/tasks/openapi.yaml b/test/support/tasks/openapi.yaml index 90107112..9c3e3db8 100644 --- a/test/support/tasks/openapi.yaml +++ b/test/support/tasks/openapi.yaml @@ -1,4 +1,24 @@ --- +components: + schemas: + Person: + example: + first_name: John + last_name: Doe + nickname: + properties: + first_name: + type: string + last_name: + type: string + nickname: + nullable: true + type: string + required: + - first_name + - last_name + - nickname + type: object info: title: Test spec version: '1.0' diff --git a/test/support/tasks/spec_module.ex b/test/support/tasks/spec_module.ex index bb657ff6..107952f5 100644 --- a/test/support/tasks/spec_module.ex +++ b/test/support/tasks/spec_module.ex @@ -18,7 +18,25 @@ defmodule OpenApiSpexTest.Tasks.SpecModule do }, servers: [ %Server{url: "http://localhost:4000"} - ] + ], + components: %{ + schemas: %{ + "Person" => %OpenApiSpex.Schema{ + type: :object, + properties: %{ + first_name: %OpenApiSpex.Schema{type: :string}, + last_name: %OpenApiSpex.Schema{type: :string}, + nickname: %OpenApiSpex.Schema{type: :string, nullable: true} + }, + required: [:first_name, :last_name, :nickname], + example: %{ + first_name: "John", + last_name: "Doe", + nickname: nil + } + } + } + } } end end