Search code examples
yamlswaggerschema

rename additionalProperties in YAML schema


I have a simple yaml file with API description where I want to use additionalProperties

openapi: 3.0.1
info:
  title: exampleApp
  version: 1.0.0
paths:
  /example:
    post:
      requestBody:
        content:
            application/json:
              schema:
                $ref: "#/components/schemas/Example"
      responses:
        '200':
          description: >
            Success.
          content:
            application/json:
              schema:
                type: string

components:
  schemas:
    Example:
      type: object
      properties:
        name: 
          type: string
        prop1:
          type: string
        additionalProperties:
          type: string

everything works fine, query is correctly mapped to query and handled in app, but I would like to rename it in schema for documentation purposes to name which I use in code. I was looking for some solution like aliases, but since it is keyword I didn't found proper solution to do this swagger output for schemas part of yaml

I want to have renamed property name in schemas part to match object name in application the output should be object like this

{
  string name;
  string prop1;
  Dictionary<string, string> CustomName;
}

Solution

  • I found solution to this problem

    components:
      schemas:
        Example:
          type: object
          properties:
            name: 
              type: string
            prop1:
              type: string
            customName:
              type: object
              additionalProperties:
                type: string
    

    this way I have clear documentation in Schemas part schemas presentation in swagger

    With this solution in Schema on swagger site is custom name visible, but the values inside can be added with various keys and are successfully mapped into Dictionary. Even if, at least for me, it looks like CustomName object could be object with property of Dictionary type