swagger-api / swagger-api/swagger-codegen

Vendor extension references not resolved

Open
#4,527 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Swagger-Parser
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When parsing a swagger file during codegen, almost all references are resolved - i.e. when producing the input file for a mustache template, the referenced YAML is inserted into the referring object.

However, this isn't happening for vendor extensions, meaning that I can't generate the docs & stubs that I need.

Swagger-codegen version

Master (as of 2017-01-09 ~09:30 UTC, i.e. 81b5b78fc2ac27070500667d139870fe63ab0012).

Swagger declaration file content or url

At the top level of the YAML spec, there are some vendor extensions. (In this case, they define common error information, used in several places throughout the rest of the API.)

x-error-defs:
  credentialTooShort:
    errorID: credentialTooShort
    message: Credential %1 is shorter than the minimum allowed (%2).
    variables:
      - The credential field which is too short.
      - The minimum permitted credential length.
  credentialTooLong:
    errorID: credentialTooLong
    message: Credential %1 is longer than the maximum allowed (%2).
    variables:
      - The credential field which is too long.
      - The maximum permitted credential length.

Within a particular response to an operation, there is a vendor extension with references to the top-level extensions. (In this case, error response objects refer to particular errors that might be returned from the operation.)


        '400':
          description: |
            The account could not be created because a credential didn't meet the complexity requirements.
          schema:
            $ref: './shared/error.yaml#/error'
          x-error-refs:
            - '$ref': '#/x-error-defs/credentialTooShort'
            - '$ref': '#/x-error-defs/credentialTooLong'
Command line used for generation

java -DdebugOperations -jar ../../../swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i credentials.yaml -l html2

Steps to reproduce

Generate API docs using the command line above for a Swagger spec. containing the YAML fragments above. Reproduces 100% of the time.

Related issues

Until yesterday, vendor extensions in responses didn't work at all. This was fixed under #4022, in so far as the extensions do now appear in the mustache input file - it's just that the references aren't being resolved.

Suggest a Fix

Fully resolve references in vendor extensions, just like in other places (e.g. parameters).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the listed Java CLI command and the YAML fragments, then inspect the generated mustache input to trace how vendor-extension references are handled. Done means references inside vendor extensions resolve like other references while generating the documentation output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, yaml
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.