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

Structural improvements: Enable the use of (atomic) definition for query, path and header parameters #693

Closed
arno-di-loreto opened this issue May 12, 2016 · 3 comments

Comments

@arno-di-loreto
Copy link
Contributor

When we define a query, path or header parameter we cannot use a reference to an existing definition.

If I create a Username definition to describe a string which is a username with a certain length and a regex pattern, I can use it in any definition I want.

But if I want to describe a Username path parameter with the same characteristics, I cannot use a schema (only availble if in value is body). So I'll have to define again the characteristics of this Username atomic definition in the UsernameParameter.

Before: Username is described twice

paths:
  /persons/{username}:
    get:
      parameters:
        - $ref: '#/parameters/UsernameParameter'
      responses:
        '200':
          description: A person
          schema:
            $ref: '#/definitions/Person'
definitions:
  Username:
    description: A person's username
    type: string
    pattern: '[a-z0-9]{8,64}'
    minLength: 8
    maxLength: 64
  Person:
    properties:
      username:
        # we can reference the atomic definition Username in any definition
        $ref: '#/definitions/Username'
      firstname:
        type: string
      lastname:
        type: string
      friends:
        type: array
        items:
          # we can reference the atomic definition Username in any definition
          $ref: '#/definitions/Friend'
  Friend:
    properties:
      username:
        $ref: '#/definitions/Username'
parameters:
  UsernameParameter:
    name: username
    in: path
    required: true
    # but we cannot reference the atomic definition Username in atomic parameters
    # username is described twice
    description: A person's username
    type: string
    pattern: '[a-z0-9]{8,64}'
    minLength: 8
    maxLength: 64

If we could use schema: Username is described only once

paths:
  /persons/{username}:
    get:
      parameters:
        - $ref: '#/parameters/UsernameParameter'
      responses:
        '200':
          description: A person
          schema:
            $ref: '#/definitions/Person'
definitions:
  Username:
    description: A person's username
    type: string
    pattern: '[a-z0-9]{8,64}'
    minLength: 8
    maxLength: 64
  Person:
    properties:
      username:
        $ref: '#/definitions/Username'
      firstname:
        type: string
      lastname:
        type: string
      friends:
        type: array
        items:
          $ref: '#/definitions/Friend'
  Friend:
    properties:
      username:
        $ref: '#/definitions/Username'
parameters:
  UsernameParameter:
    name: username
    in: path
    required: true
    # username can be used in an atomic parameted and is described once
    schema:
      $ref: '#/definitions/Username'
@arno-di-loreto
Copy link
Contributor Author

parent #565

@ePaul
Copy link
Contributor

ePaul commented May 13, 2016

For the next version, all parameters now have a schema property (added in #654). I guess this solves your problem?

@arno-di-loreto
Copy link
Contributor Author

Definitely!

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

No branches or pull requests

2 participants