Enum definitions with a single item are not included as referenced.
See original GitHub issueWhen referencing an enum with only a single value, the associated property is missing from the generated type.
I’ve attached an example directory that has a simple swagger.yaml and client output. Any help or known workarounds would be greatly appreciated.
The command run to create the client was:
cd output
autorest --typescript --add-credentials=true --input-file=../swagger.yaml --generate-metadata=true --output-folder=client --package-name="enum-single-item" --package-version=0.0.1
The output of that command, showing versions:
AutoRest code generation utility [version: 2.0.4283; node: v8.9.4]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Loading AutoRest core '/Users/bluecamel/.autorest/@microsoft.azure_autorest-core@2.0.4283/node_modules/@microsoft.azure/autorest-core/dist' (2.0.4283)
Loading AutoRest extension '@microsoft.azure/autorest.typescript' (~2.0.12->2.0.304)
Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.1.23->2.1.23)
The relevant model definitions:
definitions:
Thing:
x-ms-enum:
name: Thing
type: string
enum:
- thinger
Stuff:
properties:
message:
type: string
thing:
$ref: '#/definitions/Thing'
required:
- message
- thing
The enum is generated correctly:
/**
* Defines values for Thing.
* Possible values include: 'thinger'
* @readonly
* @enum {string}
*/
export enum Thing {
Thinger = 'thinger',
}
However, the property is missing from the generated interface that references the enum:
/**
* @interface
* An interface representing Stuff.
*/
export interface Stuff {
/**
* @member {string} message
*/
message: string;
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Enumeration types - C# reference - Microsoft Learn
You use an enumeration type to represent a choice from a set of mutually exclusive values or a combination of choices. To represent...
Read more >Handbook - Enums - TypeScript
a reference to previously defined constant enum member (which can originate from a different enum); a parenthesized constant enum expression; one of the...
Read more >typescript - Enum type not defined at runtime - Stack Overflow
I now get 'const' enums can only be used in property or index access expressions or the right hand side of an import...
Read more >Enumeration declaration - cppreference.com
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >Enums - Swagger
You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort parameter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll consider this resolved as by-design. Please follow up if you have any additional questions.
We had a need to be able to define constant-valued properties and parameters from an API design perspective and we adapted single-case enums to do so. See https://github.com/Azure/autorest/blob/master/docs/developer/guide/defining-clients-swagger.md#constants
If you poke around in ms-rest-js’s serviceClient or serializer you’ll see that at runtime we add the default values for the constant properties for you.
re x-ms-enum: you might be able to get the modeler to treat it as a user-visible string property if you want by providing
modelAsString: true
. Haven’t tried it myself.