ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
37 stars 4 forks source link

Unable to get custom types to work in swagger #3831

Closed Omzig closed 1 month ago

Omzig commented 1 month ago

Version

4.4.0

Severity

Low

Environment

Nested IIS

Steps to Reproduce

add this to a api documentation configuration

class Organization {
    [string]$id
    [string]$name
}

[Documentation()]
class ddWebhookBodyType {
    [bool]$notify
    [string]$id
    [string]$last_updated
    [string]$event_type
    [string]$title
    [string]$date
    [Organization]$org
    [string]$body
    [string]$appCode
    [string]$caseProblemCode
    [string]$transferNote
    [string]$notifyProviderGroupOnWarning
}

Expected behavior

swagger api doc body:

{
  "notify": true,
  "id": "string",
  "last_updated": "string",
  "event_type": "string",
  "title": "string",
  "date": "string",
  "org": {
          "id": "string",
          "name": "string
         },
  "body": "string",
  "appCode": "string",
  "caseProblemCode": "string",
  "transferNote": "string",
  "notifyProviderGroupOnWarning": "string"
}

Actual behavior

swagger api doc body:

{
  "notify": true,
  "id": "string",
  "last_updated": "string",
  "event_type": "string",
  "title": "string",
  "date": "string",
  "org": "string",
  "body": "string",
  "appCode": "string",
  "caseProblemCode": "string",
  "transferNote": "string",
  "notifyProviderGroupOnWarning": "string"
}

and an error at the top of swagger:
Resolver error at paths./service/dd/api/v1/Case.post.requestBody.content.application/json.schema.properties.org.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/Organization does not exist in document

Additional Environment data

No response

Screenshots/Animations

No response

Omzig commented 1 month ago

MY BAD, i was unaware that all the classes needed to be decorated:

Solution

    [Documentation()]
    class Organization {
        [string]$id
        [string]$name
    }

    [Documentation()]
    class ddWebhookBodyType {
        [bool]$notify
        [string]$id
        [string]$last_updated
        [string]$event_type
        [string]$title
        [string]$date
        [Organization]$org
        [string]$body
        [string]$appCode
        [string]$caseProblemCode
        [string]$transferNote
        [string]$notifyProviderGroupOnWarning
    }