alma-cdk / openapix

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

Cannot define x-amazon-apigateway-endpoint-configuration using openapix directly #24

Open hutchy2570 opened 2 years ago

hutchy2570 commented 2 years ago

Hi,

I would like to be able to disable the default execution endpoint of an API Gateway when using a custom domain. I tried setting disableExecuteApiEndpoint: true on the restApiProps but it appears that the SpecRestApi construct ignores this and instead expects it to be configured via the top level x-amazon-apigateway-endpoint-configuration openapi extension.

I have managed to workaround this at the moment by loading the yaml, adding the config, then manually creating the openapix schema:

  const schema = <openapix.SchemaProps>(
    yaml.load(
      fs.readFileSync(path.join(__dirname, "../schema/api.yaml"), "utf-8")
    )
  );

  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  schema["x-amazon-apigateway-endpoint-configuration"] = {
    disableExecuteApiEndpoint: true,
  };

  const openapixSchema = new openapix.Schema(schema);

  new openapix.Api(this, "MyApi", {
      source: openapixSchema,
      ...
    });

I suspect this may also be an issue when trying to configure a resource policy using x-amazon-apigateway-policy since this is also a top level extension, but I've yet to try defining this.

I'm happy to help with contributing this feature, I'm just not sure whether you'd prefer an openapix specific input property for this, or to piggyback on the restApiProps.disableExecuteApiEndpoint property. Unfortunately the SpecRestApi construct doesn't specifically say which props it ignores in favour of extensions, it just has a general statement about this being the case for some properties.