swagger-api / swagger-api/swagger-codegen

Including common definitions blocks coming from external files.

Open
#6,267 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

General: Suggestion
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Swagger-codegen version

maven-compiler-plugin 3.6.0 , swagger-core 1.5.9

Description

Each time you have to use an external definitions, you have to use the reference to the parameter in the external file. Example : - $ref: './swagger-parameters.yaml#/parameters/LanguageParameterToBeIncluded'

Is it possible to include all the external references into a local block ( by example, parameters) and the use references to your local file instead of the remote file.

Let's see the way I do now:

Common definitions to be used, declared in an external file swagger-parameters.yaml

swagger-parameters.yaml:

parameters:
  LanguageParameterToBeIncluded:
    name: language
    in: query
    description: >-
      API modifier to retrieve localised objects (when available). User
      scoped requests will default to the User's language.
    required: false
    type: string
    default: en
Here the main file

swagger-core.yaml:

swagger: '2.0'
info:
  title: swagger-core
  description: |
    This contains the common objects and definitions to be used in other projects
    This file can be included in to the other swagger files just use the ref tag
  termsOfService: |
    Property of 
  version: "${project.version}"
basePath: /wam_api/rest
parameters:
  LanguageParameterInFile:
    name: language
    in: query
    description: >-
      API modifier to retrieve localised objects (when available). User
      scoped requests will default to the User's language.
    required: false
    type: string
    default: en
paths:
  '/lines/':
    get:
      parameters:
        - $ref: './swagger-parameters.yaml#/parameters/LanguageParameterToBeIncluded'
      responses:
        '200':
          description: ''
definitions:
  TEST:
    type: object
    properties:
      test:
        type: string
Is it possible to do something like this ? ->
swagger: '2.0'
info:
  title: swagger-core
  description: |
    This contains the common objects and definitions to be used in other projects
    This file can be included in to the other swagger files just use the ref tag
  termsOfService: |
    Property of 
  version: "${project.version}"
basePath: /wam_api/rest
parameters:
  $ref: './swagger-parameters.yaml#/parameters'
paths:
  '/lines/':
    get:
      parameters:
        - $ref: '#/parameters/LanguageParameterToBeIncluded'
      responses:
        '200':
          description: ''
definitions:
  TEST:
    type: object
    properties:
      test:
        type: string

Thank-you for your excellent work.

Kind regards

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

The examples use swagger-core.yaml and swagger-parameters.yaml, but no repository files or tests are named. Start by locating the external $ref resolution entry point and its tests; done means a parameters block can import the external block and local references resolve as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.