How to express an "any" type for a property.
See original GitHub issueI’m trying to work out how to express a property that’s an “any” type using swagger and autorest. What I found through searching the web is that in swagger 2.0 you need to simply remove the “type” for a property to say its an any which if you look at my value property you’ll see I’ve done:
"CardAction": {
"description": "A clickable action",
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/ActionTypes",
"description": "The type of action implemented by this button"
},
"title": {
"description": "Text description which appears on the button",
"type": "string"
},
"image": {
"description": "Image URL which will appear on the button, next to text label",
"type": "string"
},
"text": {
"description": "Text for this action",
"type": "string"
},
"displayText": {
"description": "(Optional) text to display in the chat feed if the button is clicked",
"type": "string"
},
"value": {
"description": "Supplementary parameter for action. Content of this property depends on the ActionType"
}
}
}
But when I run this through autorest using the --typescript
switch get a mapping to type object
in the generated mapper.ts
file which causes the generated client to fail the outbound serialization for non-object values:
export const CardAction = {
required: false,
serializedName: 'CardAction',
type: {
name: 'Composite',
className: 'CardAction',
modelProperties: {
type: {
required: false,
serializedName: 'type',
type: {
name: 'String'
}
},
title: {
required: false,
serializedName: 'title',
type: {
name: 'String'
}
},
image: {
required: false,
serializedName: 'image',
type: {
name: 'String'
}
},
text: {
required: false,
serializedName: 'text',
type: {
name: 'String'
}
},
displayText: {
required: false,
serializedName: 'displayText',
type: {
name: 'String'
}
},
value: {
required: false,
serializedName: 'value',
type: {
name: 'Object'
}
}
}
}
};
Is this just a bug in the typescript plugin?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
typescript interface require one of two properties to exist
I've been playing with this example so I can better understand it. It appears that if you give component and click a type...
Read more >[@types/express] Latest types throw Property 'headers', 'body ...
I tried using the @types/express package and had problems. I tried using the latest stable ... Property 'headers' does not exist on type...
Read more >Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >How To Create Custom Types in TypeScript - DigitalOcean
In this section, you are going create types that can be used to describe any object shape you need to use in your...
Read more >5 Common Methods of Holding Real Property Title
There are different ways, all determined by state law, for an individual to ... real estate is a type of property that's made...
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
Awesome! Thanks @olydis. We already have a post processing script to do other similar fixups so I should be good. Thanks again for the quick turn around 😃
@Stevenic The legendary @amarzavery has spoken: He’ll update
ms-rest-js
(should be tagged here soon) to allow you to writeLong term, this will be what AutoRest generates for your Swagger, but well, you know about the issue tracking that 😉 Until then, I’ll happily assist you to hack something into your generation command that’ll replace
Object
withAny
for that property, in case manually changing that is not feasible (e.g. if you expect to regen very frequently, which would always override your fix…)