alma-cdk / openapix

Combine the power of AWS CDK & OpenAPI YAML Schema Definitions
https://constructs.dev/packages/@alma-cdk/openapix/
94 stars 6 forks source link

Top level descriptors on path #32

Closed deshartman closed 2 years ago

deshartman commented 2 years ago

Hi,

How would you handle the following JSON file, specifically the servers, description and x-param fields. These are at the same level as "get", so I tried to mock them.

<snip>
 "paths": {
    "/v1/Services/{Service}": {
      "get": {
        "description": "",
        "parameters": [
          {
            "name": "Service",
            "description": "some description.",
            "required": true
          },
        ],
      },
     "servers": [
        {
          "url": "https://some.server.com"
        }
      ],
      "description": "TODO: Resource-level docs",
      "x-param": {
        "defaultOutputProperties": [
          "identity",
          "address"
        ],
        "pathType": "instance",
        "parent": "/Services"
      },

  <snip>

Specifically the part I am struggling with is how to handle the servers, description and x-param fields. The get is fine. I tried this, but no luck

new openapix.Api(this, 'Notify_v1_Api', {
      source: path.join(__dirname, '../schema/twilio_notify_v1.json'),
      paths: { 
        "/v1/Services/{Sid}": {
          get: new openapix.LambdaIntegration(this, fetchService ),
          servers: new openapix.MockIntegration(),
          description: new openapix.MockIntegration(),
          ['x-param']: new openapix.MockIntegration(),

        },
      },
}

5:21:23 pm | CREATE_FAILED | AWS::ApiGateway::RestApi | v1ApiBE24E58A Errors found during import: Unable to create model for 'binding_enum_binding_type': Model name must be alphanumeric: binding_enum_binding_type Unable to create model for 'credential_enum_push_service': Model name must be alphanumeric: credential_enum_push_service Unable to create model for 'notification_enum_priority': Model name must be alphanumeric: notification_enum_priority Unable to create model for 'notify.v1.service': Model name must be alphanumeric: notify.v1.service Unable to create model for 'notify.v1.service.binding': Model name must be alphanumeric: notify.v1.service.binding Unable to create resource at path '/v1/Services/{Sid}': A sibling ({ServiceSid}) of this resource already has a variable path part -- only one is allowed Additionally, these warnings were found: Parse issue: attribute paths.'/v1/Services/{Sid}'.description is not of type string Unsupported security definition type 'http' for 'accountSid_authToken'. Ignoring. Unable to insert model 'v1.credential' due to an unsatisfied schema reference. Unable to insert model 'v1.service.notification' due to an unsatisfied schema reference.

deshartman commented 2 years ago

There is an example of a similar issue here on swagger, showing summary and description.

paths:
  /users/{id}:
    summary: Represents a user
    description: >
      This resource represents an individual user in the system.
      Each user is identified by a numeric `id`.
    get:
      ...
    patch:
      ...
    delete:
      ...
joni3k commented 2 years ago

Hi deshartman, thanks for reporting this. The paths object is not handled properly, I'll look for a fix.