Unable to reference vendor extension from openapi-generator mustache template
Asked Answered
S

1

6

I have an Open API 3 spec yaml file that has some x- prefixed properties. I'm trying to generate an Angular Typescript SDK using openapi-generator-cli. However when I reference the property in the template mustache, the x-prefixed property is always blank.

Example endpoint from the yaml (irrelevant stuff omitted):

/about:
  get:
    summary: Information about this API
    x-foo: getAbout

How I'm using it in the Mustache template (irrelevant stuff omitted):

{{#operation}}
  public {{x-foo}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})

(Basically I'm trying to use the x-foo parameter as the method name in the SDK that is being generated.)

The generated SDK, however, replaces {{x-foo}} with blank:

public ()

This is how I'm invoking the generator (without the newlines):

openapi-generator generate 
    --generator-name typescript-angular 
    --template-dir ./path/to/templates 
    --input-spec ./path/to/api.yml 
    --output ./output 
    --config ./path/to/config.json

How can I reference a vendor extension / x-prefixed Open API 3 property from within openapi-generator template?

Seamy answered 4/9, 2019 at 22:15 Comment(0)
S
10

Vendor Extensions are made available inside of a vendorExtensions parent property, not directly.

So to access an x-foo property from the mustache template, the example above would be:

{{#operation}}
  public {{vendorExtensions.x-foo}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})

To see the object that you're working against (eg. the parsed version of the api spec yml or json), run the generate command with the -v flag. One of the many things that will be printed out is the parsed spec.

Seamy answered 5/9, 2019 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.