Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI.Spec.merge/2 doesn't merge paths resulting in paths: nil #60

Open
florius0 opened this issue Jul 13, 2024 · 2 comments · May be fixed by #61
Open

OpenAPI.Spec.merge/2 doesn't merge paths resulting in paths: nil #60

florius0 opened this issue Jul 13, 2024 · 2 comments · May be fixed by #61

Comments

@florius0
Copy link

When running generation with additional_files, i.e.:

config :oapi_generator,
  tink: [
    reader: [
      file: "spec.yaml",
      additional_files: ["spec.additional.yaml"]
    ],
    naming: [
      base_module: Service,
      default_operation_module: Operation,
      operation_use_tags: true,
      field_casing: :snake
    ],
    output: [
      base_module: Service,
      location: "lib/service",
      default_client: Service.Client,
      operation_use: Service.Encoder,
      extra_fields: [:__meta__]
    ]
  ]

OpenAPI.Spec.merge/2's second clause is being called, and it doesn't set paths in resulting spec.

 @spec merge(t | nil, t) :: t
  defp merge(nil, spec_two), do: spec_two

  defp merge(spec_one, spec_two) do
    %__MODULE__{
      openapi: openapi_one,
      info: info_one,
      servers: servers_one,
      components: components_one,
      security: security_one,
      tags: tags_one,
      external_docs: external_docs_one
    } = spec_one

    %__MODULE__{
      servers: servers_two,
      components: components_two,
      security: security_two,
      tags: tags_two
    } = spec_two

    %__MODULE__{
      openapi: openapi_one,
      info: info_one,
      servers: servers_one ++ servers_two,
      components: Components.merge(components_one, components_two),
      security: security_one ++ security_two,
      tags: tags_one ++ tags_two,
      external_docs: external_docs_one
    }
  end

IMO we should merge Path.Item's, smth like:

...
path_items: Map.merge(paths_one, paths_two, Path.Item.merge/3)
...

I'll implement it shortly.

florius0 added a commit to florius0/open-api-generator that referenced this issue Jul 13, 2024
@florius0 florius0 linked a pull request Jul 13, 2024 that will close this issue
@aj-foster
Copy link
Owner

Hi @florius0, thanks for reporting this and for the PR. Do you have an example spec for this, or are the additional files created by you? I'd love to take a look, because there might be other places in the code where I made some bad assumptions about how multiple files should come together.

@florius0
Copy link
Author

Hi, I don't suppose that I should share the real specs I got this error on, they are some 30k LOC :D, but I may be able to write example specs this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants