Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
830 stars 92 forks source link

Incorrect OpenAPI Schema Generation with `New-PodeOAObjectProperty` and `-NoProperties` Parameter #1367

Closed mdaneri closed 2 weeks ago

mdaneri commented 1 month ago

Describe the Bug

When using New-PodeOAObjectProperty with the -AdditionalProperties parameter and the -NoProperties switch, the generated OpenAPI schema incorrectly includes an empty properties array.

Steps To Reproduce

  1. Run the following PowerShell command:

    New-PodeOAObjectProperty -Name 'HeaderFields' -AdditionalProperties (New-PodeOAStringProperty) -NoProperties | Add-PodeOAComponentSchema -Name 'test'
  2. This generates the following incorrect OpenAPI YAML:

    components: 
      schemas: 
        test: 
          type: object
          properties: []
          additionalProperties: 
            type: string

The properties: [] array should not be present.

Expected Behavior

The generated OpenAPI YAML should not include the properties: [] array when the -NoProperties switch is used. The corrected YAML should look like this:

components: 
  schemas: 
    test: 
      type: object
      additionalProperties: 
        type: string

Fix

Ensure that the properties array is omitted from the generated OpenAPI schema when the -NoProperties switch is used.