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

Example on object with additionalProperties is cast to map #62

Closed
dickermoshe opened this issue Mar 12, 2024 · 4 comments
Closed

Example on object with additionalProperties is cast to map #62

dickermoshe opened this issue Mar 12, 2024 · 4 comments

Comments

@dickermoshe
Copy link
Contributor

Shoulnt example always be a string?

Details

components:
  requestBodies:
    nested_response:
      content:
        "*/*":
          schema:
            properties:
              id:
                type: string
              password:
                type: string
            required:
              - id
            type: object
      required: true
  schemas:
    ObjectOfObjects:
      description: An object of objects
      properties:
        inner:
          $ref: "#/components/schemas/ObjectOfObjects_inner"
      type: object
    ObjectOfObjects_inner:
      properties:
        optional_thing:
          type: integer
        required_thing:
          type: string
      required:
        - required_thing
      type: object
    aNullableContainer:
      properties:
        NullableThing:
          nullable: true
          type: string
        RequiredNullableThing:
          nullable: true
          type: string
      required:
        - RequiredNullableThing
      type: object
    additionalPropertiesObject:
      additionalProperties:
        type: string
      description: An additionalPropertiesObject
      example: foo
      type: object
    allOfObject:
      allOf:
        - $ref: "#/components/schemas/baseAllOf"
      example:
        sampleProperty: sampleProperty
      properties:
        sampleProperty:
          type: string
    baseAllOf:
      properties:
        sampleBaseProperty:
          type: string
      type: object
    dummyPut_request:
      properties:
        id:
          type: string
        password:
          type: string
      required:
        - id
      type: object
    get_yaml_response:
      description: structured response
      properties:
        value:
          description: Inner string
          type: string
      type: object
info:
  description: This spec is for testing rust-server-specific things
  title: rust-server-test
  version: 2.3.4
openapi: 3.0.1
paths:
  /allOf:
    get:
      description: Test getting an object which uses allOf
      operationId: AllOf_Get
      responses:
        "200":
          content:
            "*/*":
              schema:
                $ref: "#/components/schemas/allOfObject"
          description: OK
  /dummy:
    get:
      operationId: dummyGet
      responses:
        "200":
          content: {}
          description: Success
      summary: A dummy endpoint to make the spec valid.
    put:
      operationId: dummyPut
      requestBody:
        content:
          "*/*":
            schema:
              $ref: "#/components/schemas/dummyPut_request"
        required: true
      responses:
        "200":
          content: {}
          description: Success
      x-codegen-request-body-name: nested_response
  /file_response:
    get:
      operationId: file_responseGet
      responses:
        "200":
          content:
            application/json:
              schema:
                format: binary
                type: string
          description: Success
      summary: Get a file
  /get-structured-yaml:
    get:
      description: Test returning arbitrary structured YAML
      operationId: getStructuredYaml
      responses:
        "200":
          content:
            application/yaml:
              schema:
                $ref: "#/components/schemas/get_yaml_response"
          description: OK
  /html:
    post:
      operationId: htmlPost
      requestBody:
        content:
          text/html:
            schema:
              type: string
        required: true
      responses:
        "200":
          content:
            text/html:
              schema:
                type: string
          description: Success
      summary: Test HTML handling
      x-codegen-request-body-name: body
  /post-yaml:
    post:
      description: Test sending an arbitrary unsupported format - e.g. YAML
      operationId: post_yaml
      requestBody:
        content:
          application/yaml:
            schema:
              type: string
        description: The YAML body to test
        required: true
      responses:
        "204":
          content: {}
          description: OK
      x-codegen-request-body-name: value
  /raw_json:
    get:
      operationId: raw_jsonGet
      responses:
        "200":
          content:
            "*/*":
              schema:
                type: object
          description: Success
      summary: Get an arbitrary JSON blob.
  /solo-object:
    post:
      operationId: solo_objectPost
      requestBody:
        content:
          application/json:
            schema:
              type: object
        required: true
      responses:
        "204":
          content: {}
          description: OK
      summary: Send an arbitrary JSON blob
      x-codegen-request-body-name: value
servers:
  - url: /
x-original-swagger-version: "2.0"

@walsha2
Copy link
Contributor

walsha2 commented Mar 12, 2024

additionalPropertiesObject:
  additionalProperties:
    type: string
  description: An additionalPropertiesObject
  example: foo
  type: object

Again, as with #63 - I am not really sure what is happening here. additionalPropertiesObject is an object so the example should be a map. See https://swagger.io/docs/specification/data-models/dictionaries/ and scroll down to "Examples of Dictionary Contents".

IMO, this example: foo is an incorrect spec and if that is the case, we cant really spend time coding up protections for incorrect spec configurations because those are infinite...

@dickermoshe
Copy link
Contributor Author

Then a nice warning should be thrown, I'm working on a PR that throws a clear error message when deserialization fails

@walsha2
Copy link
Contributor

walsha2 commented Mar 12, 2024

Then a nice warning should be thrown, I'm working on a PR that throws a clear error message when deserialization fails

Sounds good. Try to keep PRs small and only tackle a single, isolated, issue at a time 🙏 - makes merging and reviewing much easier.

@walsha2
Copy link
Contributor

walsha2 commented Mar 12, 2024

Resolved by #64 - closing. Will not update code to account for these edge cases, instead will throw a clear error message.

@walsha2 walsha2 closed this as completed Mar 12, 2024
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