kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

Case-insensitive enums #755

Open Cellule opened 3 years ago

Cellule commented 3 years ago

I have the following schema and I want to allow users to send body {"id": 123, "teamRole": "Admin"} However right now openapi-request-validator will consider Admin invalid because it is not part of the enum choices. I'm trying to find someway using the schema to coerce enums to the right casing. So far I can't seem to find a way to achieve this with the provided tools in this repo and I feel like there really should be something available. Any pointers appreciated

/teams/{teamId}/members: 
  post: 
    summary: "Add a member to a team"
    requestBody: 
      description: "Member to add to team"
      required: true
      content: 
        application/json: 
          schema: 
            type: "object"
            required: 
              - "id"
            properties: 
              id: 
                type: "integer"
                example: 963
                description: "Global ID of the user"
              teamRole: 
                type: "string"
                enum: 
                  - "ADMIN"
                  - "MEMBER"
                example: "MEMBER"
    responses: 
      201: 
        description: "Successfully added team member"
        content: 
          application/json: 
            schema: 
              type: "object"
              required: 
                - "id"
              properties: 
                id: 
                  type: "integer"
                  example: 963
                  description: "Global ID of the user"
    parameters: 
      - 
        schema: 
          type: "integer"
        name: "teamId"
        in: "path"
        required: true
        description: "ID of the team"
        example: "1"