How do I define a XSD like "simple type" in Swagger? - swagger

I've got a type that is just a string in my yml definition:
PlayMode:
type: string
I'd like to use in my generated code, but I get a concrete class. I'm assuming I've not set-up the yml correctly.
In an XSD, this would be a "simpleType".

Just had the same issue, but looks like it has just been fixed by the swagger team: https://github.com/swagger-api/swagger-parser/issues/243

Related

Generating domain model classes from swagger with Autorest

I'm trying to use Autorests own example to generate a client.
https://github.com/Azure/autorest/blob/main/docs/generate/readme.md
And when I run
autorest --input-file=pets.json --csharp
I get a Client class and an Options class. But it does not generate the Dog or Kitten classes for me, eventhough I can see the they are defined the pets.json file.
What am I missing here?
autorest --input-file=pets.json --csharp --generation1-convenience-client
seemed to be the answer :)

Reuse or $ref requestTemplates in yaml

It is possible to reuse schema definitions with $ref. Is there a similar method for reusing string values, like the requestTemplates for Amazon's API Gateway extensions?
I've tried these methods, but both produce errors (I am not very familiar with YAML)
requestTemplates:
$ref: "#/definitions/MappingTemplate"
definitions:
MappingTemplate:
type: "object"
properties:
application/json: "the template"
and
requestTemplates:
application/json:
$ref: "#/definitions/MappingTemplate"
definitions:
MappingTemplate: "the template"
How can I use a $ref for requestTemplates?
References are currently supported for model schemas only. However, this should be possible with a local modification to upgrade the Swagger parser version in the pom.xml file.
Yes, references are supported in many parts of the swagger definition. If you look at the specification, you will see that references are allowed for path items, parameters, model definitions, etc. And each of those can be relative (in the same file) or absolute (into different http locations).

Camel case code generation with swagger

I am trying to generate python client from a swagger yaml file. It works fine, except that the response models are all snake cased(words sep. by underscores) instead of camel cased. I provided the camel cased versions like this:
definitions:
serviceResponse:
type: object
properties:
serviceResponseInternal:
type: object
The generated code has a ServiceResponse object which has an internal field service_response_internal. I would like it to respect the convention and just have serviceResponseInternal instead of underscored seperated names. How do I achieve this?
Assuming you're using Swagger Codegen, you can customize the toVarName in the Python code generator:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java#L180
Can you elaborate on why you don't want to go with snake case for model properties (which should conform to Python style guide)?
UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator. Please refer to the Q&A for more information.

How to get grails to assign Id to a legacy Java object

I have a java annotized domain object that I want to use in grails, this works fine, however all the generated templates use Id as the primary key. I tried to create a XxxConstraints.groovy file in the same package as my domain object, and added
mapping = {
id type:'assigned', name:<name of java field>, type: string
}
but that does not seem to work.
The error I get when trying to render the gsp is "class XYZ does not contain field id"
By the way I am using grails 2.1.0.
Thanks for the help in advance.
If you're talking about scaffolding views, they just have id field hardcoded, like: <g:hiddenField name="id" value="\${${propertyName}?.id}" /> (sample from edit.gsp).
Just modify your GSPs by hand to use your key field.
If it's more than one class and you don't want to generate all the views, you can install the templates into your project sources with grails install-templates and modify those to use your PK field. Maybe Groovy wrappers for Java classes will have ident() method, though not sure.
After looking at the doc, I'm in doubt if mapping{} DSL will work at all. Looks like only constraints section will work, and I believe you only need #Id annotation.

BizTalk namespace default prefix

BizTalk produced namespace default prefix as NS0. Is there a way to override it to generate something different without utilizing an XSLT (it's an overhead when the schema changes, XSLT has to be updated as well)? Something like
<pidx:Invoice>
and not
<ns0:Invoice>
This should be simple (after all it's just a namespace prefix), but clients are parsing document instead of using it as an XML with namespace, and having no expected namespace prefix causes them grief.
Thank you.
No, there's not.
A kludgey answer is to convert the XML to a string and search/replace.
You can do this. I had to do this when calling a Google API, which requires specific namespace prefixes.
The method is to use the Imports property at the <Schema> level in your XSD. Using the Imports dialog you can define specific prefixes on each namespace.
You will have to break up your schema into at least two separate XSD's so you can import one into the other and redefine the prefix at that time.

Resources