We are using swagger-codegen-maven-plugin to generate our model classes from spec file.
I know we can make a field hidden by using hidden=true in ApiModelProperty. Is there a way this can be set in the spec , so that codegen automatically adds hidden property to the field ?
Related
Swagger & Swagger UI use "Schemas" and "Models" interchangeably. I'd like to refer to them as Models on my Swagger UI instance (rather than Schemas), but can't find where to make this change.
I've attached 2 images that show where I'm referring to. I'd like to erase all references of "Schemas" from the page, and replace them with "Model", similar to how it appears on many of Swagger's test sites (example: petstore.swagger.io) that they've created.
Image 1
Image 2
Swagger & Swagger UI use "Schemas" and "Models" interchangeably.
Just to clarify - Swagger UI uses "Schema" when rendering OpenAPI 3 definitions, and "Model" when rendering OpenAPI 2.0 definitions. With this in mind, "Model" is sort of an outdated term.
If you still want to see the "Model" label in Swagger UI regardless of your OpenAPI version, you'll have to fork Swagger UI, change the label in the code, and build and use your own version. (And rebuild it whenever you want to use a newer Swagger UI release.)
The lines you need to change are:
src/core/components/model-example.jsx
{isOAS3 ? "Schema" : "Model" }
change to
"Model"
src/core/components/models.jsx
<span>{isOAS3 ? "Schemas" : "Models"}</span>
change to
<span>"Models"</span>
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.
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.
I have a custom external XJB file that has the schema name within it as follows :
jxb:bindings schemaLocation="completeCheck.xsd" node="/xs:schema"
Just wondering, is there a way to substitute the schema name at runtime within the XJB file using ANT(using ANT XJC) OR have a xjb binding file written such that I do not have to hardcode the schema name in it. Basically, I am trying to see if I can use a single xjb file for multiple XSDs.
Currently, I have the same xjb file all over the place with a different hardcoded schema name referred all over the place in build.xml. Any pointers are highly appreciated. I am using JAXB 2.x
Make a template from your xjb file by replacing the value of your schemaLocation attribute with some sort of marker (e.g. !!!) and save it using some other name/extension. Define a macro with an attribute such as schema-name that will use ant's replace to change the marker in the template file with your schema name and save that as the binding file to be subsequently used by xjc.
Normally, in the latest versions of XJC, you can use schema component designator. More info here :
https://jaxb.java.net/nonav/2.2.1/docs/vendorCustomizations.html#scd and https://jaxb.java.net/guide/Using_SCD_for_customizations.html
This field is part of a custom list definition in a feature. Originally this was a required field. The change to not being required was done simply by removing the "Required='TRUE'" from the schema.xml, packaged as a solution, deployed via stsadm -o upgradesolution, etc.
It works as it should on my dev box but not on staging. I've compared the field element xml strings and they are identical (via SP Manager 2007).
I've tried setting it to required and back again via the UI, no change.
Any ideas?
Is this field used in a Content Type? If yes, then you might have to remove the Required='TRUE' from the Content Type section of the schema as well. Or if this field or its content type is declared at the web level, make sure you change the required attribute at that level as well.