Skip to content

Are there any plans to add support for yaml media type examples? #6857

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

Closed
mathis-m opened this issue Jan 20, 2021 · 1 comment · Fixed by #6858
Closed

Are there any plans to add support for yaml media type examples? #6857

mathis-m opened this issue Jan 20, 2021 · 1 comment · Fixed by #6858

Comments

@mathis-m
Copy link
Contributor

mathis-m commented Jan 20, 2021

Are there any plans to add support for yaml media type examples? Currently examples given as schema objects will render as either json or xml, but to get them to display as yaml I must copy and paste a separate example as a multi-line string.

Here is an example spec demonstrating the different behaviours:

openapi: 3.0.0
info:
  version: '0.1'
  title: Yaml vs Json Examples
  description: ''
paths:
  /resource1:
    post:
      summary: Add some resource - examples are json or xml
      operationId: myOp1
      responses:
        '201':
          description: resource created
        '400':
          description: Invalid input
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsJson:
                $ref: '#/components/examples/example1'
          application/yaml:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsJson:
                $ref: '#/components/examples/example1'
          application/xml:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsXml:
                $ref: '#/components/examples/example1'                 
        description: Resource to add 
  /resource2:
    post:
      summary: Add some resource - examples are string or yaml
      operationId: myOp2
      responses:
        '201':
          description: resource created
        '400':
          description: Invalid input
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsString:
                $ref: '#/components/examples/example2'
          application/yaml:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsYaml:
                $ref: '#/components/examples/example2' 
          application/xml:
            schema:
              $ref: '#/components/schemas/ModelA'
            examples:
              willRenderAsYaml:
                $ref: '#/components/examples/example2'          
        description: Resource to add         
components:
  examples:
    example1:
      summary: Example as schema object
      value:
        PropertyA: foo
        PropertyB: bar
    # to get example1 to show as YAML have to copy paste 
    # and pipe the value
    example2:
      summary: Example as literal YAML string
      value: |
        PropertyA: foo
        PropertyB: bar        
  schemas:
    ModelA:
      type: object
      properties:
        PropertyA:
          type: string
        PropertyB:
          type: string

Thanks

Originally posted by @deltafsdevelopment in #6470 (comment)

@mathis-m mathis-m changed the title Are there any plans to add support for yaml media type examples? Currently examples given as schema objects will render as either json or xml, but to get them to display as yaml I must copy and paste a separate example as a multi-line string. Are there any plans to add support for yaml media type examples? Jan 20, 2021
@tim-lai
Copy link
Contributor

tim-lai commented Jan 21, 2021

reposting from my comment in PR #6858:

So... while application/yaml isn't an actual media type, and that there exists multiple ways to express yaml, e.g. 'text/yaml', based on the xml implementation as precedence, we can move forward with this as a new feature.

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