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

Explore generics possibilities #148

Open
kbuntrock opened this issue Aug 4, 2024 · 0 comments
Open

Explore generics possibilities #148

kbuntrock opened this issue Aug 4, 2024 · 0 comments

Comments

@kbuntrock
Copy link
Owner

kbuntrock commented Aug 4, 2024

Explore new openapi 3.1 generic possibilities

See

And example (https://editor-next.swagger.io):

openapi: 3.1.0
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
servers:
  - url: https://petstore3.swagger.io/api/v3
tags:
  - name: user
    description: Operations about user
paths:
  /user:
    post:
      tags:
        - user
      summary: Create user
      description: This can only be done by the logged in user.
      operationId: createUser
      requestBody:
        description: Created user object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      responses:
        default:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/objWithTypedArray'
  /user/createWithList:
    post:
      tags:
        - user
      summary: Creates list of users with given input array
      description: Creates list of users with given input array
      operationId: createUsersWithListInput
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/User'
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PageUser'  
        default:
          description: successful operation
components:
  schemas:
    User:
      $id: User.Id
      type: object
      properties:
        id:
          type: integer
          format: int64
        username:
          type: string
        firstName:
          type: string
        lastName:
          type: string
    Page:
      $id: PageId
      type: object
      properties:
        content:
          type: array
          items: 
            $dynamicRef: "#page.content"
          $defs:
          allowAll:
            $dynamicAnchor: page.content
        first:
          type: boolean
        last:
          type: boolean
        totalElements:
          type: number
        totalPages:
          type: number
    PageUser:
      $id: page.user
      $ref: PageId
      $defs:
        pageOfUser:
          $dynamicAnchor: page.content
          type: object
          $ref: User.Id
    genericArrayComponent:
      $id: fully_generic_array
      type: array
      items:
        $dynamicRef: "#generic-array"
      $defs:
        allowAll:
          $dynamicAnchor: generic-array
    numberArray:
      $id: array_of_numbers
      $ref: fully_generic_array
      $defs:
        numbersOnly:
          $dynamicAnchor: generic-array
          type: number
    stringArray:
      $id: array_of_strings
      $ref: fully_generic_array
      $defs:
        stringsOnly:
          $dynamicAnchor: generic-array
          type: string
    objWithTypedArray:
      $id: obj_with_typed_array
      type: object
      required: 
      - dataType 
      - data
      properties:
        dataType:
          enum:
          - string
          - number
      oneOf:
      - properties:
          dataType:
            const: string
          data:
            $ref: array_of_strings
      - properties:
          dataType:
            const: number
          data:
            $ref: array_of_numbers
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

1 participant