aj-foster / open-api-generator

Open API code generator for Elixir
MIT License
97 stars 13 forks source link

Key "name" not found for parameter reference #53

Closed col closed 2 months ago

col commented 2 months ago

Just tried to generate my first client and hit this issue. I think using $ref for a parameter definition is pretty standard and looking at the spec doc it appears to be done correctly. Any ideas?

19:01:11.349 [debug] Reading file circleci_spec.json
** (KeyError) key "name" not found in: %{"$ref" => "#/components/parameters/usage_export_job_id"}
    :erlang.map_get("name", %{"$ref" => "#/components/parameters/usage_export_job_id"})
    (oapi_generator 0.1.1) lib/open_api/spec/path/parameter.ex:51: OpenAPI.Spec.Path.Parameter.decode/2
    (oapi_generator 0.1.1) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.1) lib/open_api/spec/path/item.ex:137: anonymous fn/2 in OpenAPI.Spec.Path.Item.decode_parameters/2
    (elixir 1.16.3) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (oapi_generator 0.1.1) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4
    (oapi_generator 0.1.1) lib/open_api/spec/path/item.ex:42: OpenAPI.Spec.Path.Item.decode/2
    (oapi_generator 0.1.1) lib/open_api/reader/state.ex:111: OpenAPI.Reader.State.with_path/4

Here's what I think is the relevant snippet from the spec.

paths:
  /organizations/{org_id}/usage_export_job/{usage_export_job_id}:
    parameters:
      - $ref: '#/components/parameters/org_id'
      - $ref: '#/components/parameters/usage_export_job_id'
components:
  parameters:
    usage_export_job_id:
      name: usage_export_job_id
      description: An opaque identifier of a usage export job.
      example: e8235eed-f121-4ae3-9c72-2719d6572818
      in: path
      required: true
      schema:
        type: string
        format: uuid

Note: I'm using a YAML version of the spec but the original from CircleCI is in json format. The same error occurs using either format though.

Link to original spec doc: https://circleci.com/docs/api/v2/index.html (there is a download link at the top)

aj-foster commented 2 months ago

Hi @col, thanks for reporting this. Looks like I forgot to add ref support for params that are listed at the Path Item level (instead of the Operation level). It's now fixed on main if you'd like to try it out! ❤️