Skip to content
Snippets Groups Projects

Tests/openapi generator

Merged Johannes Mey requested to merge tests/openapi-generator into main
2 files
+ 1910
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 934
0
import io.swagger.models.*;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.*;
import io.swagger.v3.oas.models.callbacks.*;
import io.swagger.v3.oas.models.examples.*;
import io.swagger.v3.oas.models.headers.*;
import io.swagger.v3.oas.models.info.*;
import io.swagger.v3.oas.models.links.*;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.parameters.*;
import io.swagger.v3.oas.models.responses.*;
import io.swagger.v3.oas.models.security.*;
import io.swagger.v3.oas.models.servers.*;
import io.swagger.v3.oas.models.tags.*;
aspect Parser {
public static OpenAPIObject OpenAPIObject.parseOpenAPI(OpenAPI api) {
OpenAPIObject openapi = new OpenAPIObject();
if (api.getOpenapi() != null)
openapi.setOpenAPI(api.getOpenapi());
if (api.getInfo() != null)
openapi.set_impl_i(InfoObject.parseInfo(api.getInfo()));
if (api.getPaths() != null) {
for (String key : api.getPaths().keySet())
openapi.addP(new PathsObject(key, PathItemObject.parsePath(api.getPaths().get(key))));
}
if (api.getServers() != null) {
for (io.swagger.v3.oas.models.servers.Server s : api.getServers())
openapi.addS(ServerObject.parseServer(s));
}
if (api.getComponents() != null)
openapi.set_impl_c(ComponentsObject.parseComponents(api.getComponents()));
if (api.getSecurity() != null) {
for (io.swagger.v3.oas.models.security.SecurityRequirement s : api.getSecurity())
openapi.addSr(SecurityRequirementObject.parseSecurityRequirement(s));
}
if (api.getTags() != null) {
for (io.swagger.v3.oas.models.tags.Tag t : api.getTags())
openapi.addT(TagObject.parseTag(t));
}
if (api.getExternalDocs() != null)
openapi.set_impl_e(ExternalDocObject.parseExternalDocs(api.getExternalDocs()));
if (api.getExtensions().size() != 0) {
for (String key : api.getExtensions().keySet())
openapi.addEx(new Extension(key, api.getExtensions().get(key)));
}
/* 3.1.0 features
if (api.getWebhook != null) ...
if (api.getJsonSchemaDialect != null) ...
*/
return openapi;
}
public static InfoObject InfoObject.parseInfo(io.swagger.v3.oas.models.info.Info info) {
InfoObject infoObject = new InfoObject();
if (info.getTitle() != null)
infoObject.setTitle(info.getTitle());
if (info.getVersion() != null)
infoObject.setVersion(info.getVersion());
if (info.getDescription() != null)
infoObject.setDescription(info.getDescription());
if (info.getTermsOfService() != null)
infoObject.setTermsOfService(info.getTermsOfService());
if (info.getContact() != null)
infoObject.set_impl_c(ContactObject.parseContact(info.getContact()));
if (info.getLicense() != null)
infoObject.set_impl_l(LicenseObject.parseLicense(info.getLicense()));
if (info.getExtensions().size() != 0) {
for (String key : info.getExtensions().keySet())
infoObject.addEx(new Extension(key, info.getExtensions().get(key)));
}
/* 3.1.0 features
if (info.getSummary != null) ...
*/
return infoObject;
}
public static ContactObject ContactObject.parseContact(io.swagger.v3.oas.models.info.Contact contact){
ContactObject contactObject = new ContactObject();
if (contact.getName() != null)
contactObject.setName(contact.getName());
if (contact.getUrl() != null)
contactObject.setUrl(contact.getUrl());
if (contact.getEmail() != null)
contactObject.setEmail(contact.getEmail());
if (contact.getExtensions().size() != 0) {
for (String key : contact.getExtensions().keySet())
contactObject.addEx(new Extension(key, contact.getExtensions().get(key)));
}
return contactObject;
}
public static LicenseObject LicenseObject.parseLicense(io.swagger.v3.oas.models.info.License license){
LicenseObject licenseObject = new LicenseObject();
if (license.getName() != null)
licenseObject.setName(license.getName());
if (license.getUrl() != null)
licenseObject.setUrl(license.getUrl());
if (license.getExtensions().size() != 0) {
for (String key : license.getExtensions().keySet())
licenseObject.addEx(new Extension(key, license.getExtensions().get(key)));
}
/* 3.1.0 features
if (license.getIdentifier() != null) ...
*/
return licenseObject;
}
public static ServerObject ServerObject.parseServer(Server server){
ServerObject serverObject = new ServerObject();
if (server.getUrl() != null)
serverObject.setUrl(server.getUrl());
if (server.getDescription() != null)
serverObject.setDescription(server.getDescription());
if (server.getVariables() != null) {
for (String key : server.getVariables().keySet())
serverObject.addSt(new ServerVariablesTuple(key, ServerVariableObject.parseServerVariable(server.getVariables().get(key))));
}
if (server.getExtensions().size() != 0) {
for (String key : server.getExtensions().keySet())
serverObject.addEx(new Extension(key, server.getExtensions().get(key)));
}
return serverObject;
}
public static ServerVariableObject ServerVariableObject.parseServerVariable(ServerVariable serverVariable){
ServerVariableObject serverVariableObject = new ServerVariableObject();
if (serverVariable.getDefault() != null)
serverVariableObject.setDefault(serverVariable.getDefault());
if (serverVariable.getDescription() != null)
serverVariableObject.setDescription(serverVariable.getDescription());
if (serverVariable.getEnum().size() != 0) {
for (String e : serverVariable.getEnum())
serverVariableObject.addE(new Enum(e));
}
if (serverVariable.getExtensions().size() != 0) {
for (String key : serverVariable.getExtensions().keySet())
serverVariableObject.addEx(new Extension(key, serverVariable.getExtensions().get(key)));
}
return serverVariableObject;
}
public static ComponentsObject ComponentsObject.parseComponents(Components components) {
ComponentsObject componentsObject = new ComponentsObject();
if (components.getSchemas() != null) {
for (String key : components.getSchemas().keySet())
componentsObject.addS(new SchemaTuple(key, SchemaOb.parseSchema(components.getSchemas().get(key))));
}
if (components.getResponses() != null) {
for (String key : components.getResponses().keySet())
componentsObject.addR(new ResponseTuple(key, ResponseOb.parseResponse(components.getResponses().get(key))));
}
if (components.getParameters() != null) {
for (String key : components.getParameters().keySet())
componentsObject.addP(new ParameterTuple(key, ParameterOb.parseParameter(components.getParameters().get(key))));
}
if (components.getExamples() != null) {
for (String key : components.getExamples().keySet())
componentsObject.addE(new ExampleTuple(key, ExampleObject.parseExample(components.getExamples().get(key))));
}
if (components.getRequestBodies() != null) {
for (String key : components.getRequestBodies().keySet())
componentsObject.addRb(new RequestBodyTuple(key, RequestBodyOb.parseRequestBody(components.getRequestBodies().get(key))));
}
if (components.getHeaders() != null) {
for (String key : components.getHeaders().keySet())
componentsObject.addH(new HeaderTuple(key, HeaderOb.parseHeader(components.getHeaders().get(key))));
}
if (components.getSecuritySchemes() != null) {
for (String key : components.getSecuritySchemes().keySet())
componentsObject.addSc(new SecuritySchemeTuple(key, SecuritySchemeOb.parseSecurityScheme(components.getSecuritySchemes().get(key))));
}
if (components.getLinks() != null) {
for (String key : components.getLinks().keySet())
componentsObject.addL(new LinkTuple(key, LinkOb.parseLink(components.getLinks().get(key))));
}
if (components.getCallbacks() != null) {
for (String key : components.getCallbacks().keySet())
componentsObject.addC(new CallbackTuple(key, CallbackOb.parseCallback(components.getCallbacks().get(key))));
}
if (components.getExtensions().size() != 0) {
for (String key : components.getExtensions().keySet())
componentsObject.addEx(new Extension(key, components.getExtensions().get(key)));
}
/* 3.1.0 features
if (components.getPathItems() != null) ...
*/
return componentsObject;
}
public static PathItemOb PathItemOb.parsePath(PathItem path) {
PathItemObject pathItem = new PathItemObject();
if(path.get$ref() != null){
PathItemReference r = new PathItemReference();
r.setRef(path.get$ref());
/* 3.1.0 features
if (path.getSummary() != null) ...
if (path.getDescription() != null) ...
if (path.getPathItem() != null) ...
*/
return r;
} else
if (path.getSummary() != null)
pathItem.setSummary(path.getSummary());
if (path.getDescription() != null)
pathItem.setDescription(path.getDescription());
if (path.getGet() != null) {
Get get = new Get();
get.set_impl_o(OperationObject.parseOperation(path.getGet()));
pathItem.setG(get);
}
if (path.getPut() != null) {
Put put = new Put();
put.set_impl_o(OperationObject.parseOperation(path.getPut()));
pathItem.setPut(put);
}
if (path.getPost() != null) {
Post post = new Post();
post.set_impl_o(OperationObject.parseOperation(path.getPost()));
pathItem.setPost(post);
}
if (path.getDelete() != null) {
Delete delete = new Delete();
delete.set_impl_o(OperationObject.parseOperation(path.getDelete()));
pathItem.set_impl_d(delete);
}
if (path.getOptions() != null) {
Options options = new Options();
options.set_impl_o(OperationObject.parseOperation(path.getOptions()));
pathItem.set_impl_o(options);
}
if (path.getHead() != null) {
Head head = new Head();
head.set_impl_o(OperationObject.parseOperation(path.getHead()));
pathItem.setH(head);
}
if (path.getPatch() != null) {
Patch patch = new Patch();
patch.set_impl_o(OperationObject.parseOperation(path.getPatch()));
pathItem.setP(patch);
}
if (path.getTrace() != null) {
Trace trace = new Trace();
trace.set_impl_o(OperationObject.parseOperation(path.getTrace()));
pathItem.setT(trace);
}
if (path.getServers() != null) {
for (Server s : path.getServers())
pathItem.addS(ServerObject.parseServer(s));
}
if (path.getParameters() != null) {
for (Parameter p : path.getParameters())
pathItem.addPo(ParameterOb.parseParameter(p));
}
if (path.getExtensions().size() != 0) {
for (String key : path.getExtensions().keySet())
pathItem.addEx(new Extension(key, path.getExtensions().get(key)));
}
return pathItem;
}
public static OperationObject OperationObject.parseOperation(io.swagger.v3.oas.models.Operation operation) {
OperationObject operationObject = new OperationObject();
if (operation.getDeprecated() != null)
operationObject.setDeprecatedBoolean(operation.getDeprecated());
if (operation.getTags() != null) {
for (String t : operation.getTags()) {
de.tudresden.inf.st.openapi.ast.Tag tag = new de.tudresden.inf.st.openapi.ast.Tag();
tag.setTag(t);
operationObject.addT(tag);
}
}
if (operation.getSummary() != null)
operationObject.setSummary(operation.getSummary());
if (operation.getDescription() != null)
operationObject.setDescription(operation.getDescription());
if (operation.getExternalDocs() != null)
operationObject.set_impl_ed(ExternalDocObject.parseExternalDocs(operation.getExternalDocs()));
if (operation.getOperationId() != null)
operationObject.setOperationID(operation.getOperationId());
if (operation.getParameters() != null) {
for (Parameter p : operation.getParameters())
operationObject.addP(ParameterOb.parseParameter(p));
}
if (operation.getRequestBody() != null)
operationObject.set_impl_rb(RequestBodyOb.parseRequestBody(operation.getRequestBody()));
if (operation.getResponses().size() != 0) {
ResponsesObject r = new ResponsesObject();
for (String key : operation.getResponses().keySet())
r.addR(new ResponseTuple(key, ResponseObject.parseResponse(operation.getResponses().get(key))));
operationObject.set_impl_r(r);
}
if (operation.getCallbacks().size() != 0) {
for (String key : operation.getCallbacks().keySet())
operationObject.addC(new CallbackTuple(key, CallbackObject.parseCallback(operation.getCallbacks().get(key))));
}
if (operation.getSecurity().size() != 0) {
for (io.swagger.v3.oas.models.security.SecurityRequirement s : operation.getSecurity())
operationObject.addSr(SecurityRequirementObject.parseSecurityRequirement(s));
}
if (operation.getServers() != null) {
for (Server s : operation.getServers())
operationObject.addS(ServerObject.parseServer(s));
}
if (operation.getExtensions().size() != 0) {
for (String key : operation.getExtensions().keySet())
operationObject.addEx(new Extension(key, operation.getExtensions().get(key)));
}
return operationObject;
}
public static ExternalDocObject ExternalDocObject.parseExternalDocs(ExternalDocumentation externalDocs){
ExternalDocObject externalDocObject = new ExternalDocObject();
if (externalDocs.getDescription() != null)
externalDocObject.setDescription(externalDocs.getDescription());
if (externalDocs.getUrl() != null)
externalDocObject.setUrl(externalDocs.getUrl());
if (externalDocs.getExtensions() != null) {
for (String key : externalDocs.getExtensions().keySet())
externalDocObject.addEx(new Extension(key, externalDocs.getExtensions().get(key)));
}
return externalDocObject;
}
public static ParameterOb ParameterOb.parseParameter(Parameter parameter) {
ParameterObject parameterObject = new ParameterObject();
if (parameter.get$ref() != null) {
ParameterReference p = new ParameterReference();
p.setRef(parameter.get$ref());
/* 3.1.0 features
if (parameter.getSummary() != null) ...
if (parameter.getDescription() != null) ...
if (parameter.getParameter() != null) ...
*/
return p;
} else {
if (parameter.getName() != null)
parameterObject.setName(parameter.getName());
if (parameter.getIn() != null)
parameterObject.setIn(parameter.getIn());
if (parameter.getDescription() != null)
parameterObject.setDescription(parameter.getDescription());
if (parameter.getDeprecated() != null)
parameterObject.setDeprecatedBoolean(parameter.getDeprecated());
if (parameter.getStyle() != null)
parameterObject.setStyle(parameter.getStyle().toString());
if (parameter.getExplode() != null)
parameterObject.setExplode(parameter.getExplode());
if (parameter.getAllowReserved() != null)
parameterObject.setAllowReserved(parameter.getAllowReserved());
if (parameter.getSchema() != null)
parameterObject.set_impl_s(SchemaOb.parseSchema(parameter.getSchema()));
if (parameter.getExample() != null)
parameterObject.setExample(parameter.getExample());
if (parameter.getExamples() != null) {
for (String key : parameter.getExamples().keySet())
parameterObject.addE(new ExampleTuple(key, ExampleObject.parseExample(parameter.getExamples().get(key))));
}
if (parameter.getContent() != null) {
for (String key : parameter.getContent().keySet())
parameterObject.addC(new ContentTuple(key, MediaTypeObject.parseMediaType(parameter.getContent().get(key))));
}
if (parameter.getRequired() != null)
parameterObject.setRequired(parameter.getRequired());
if (parameter.getExtensions().size() != 0) {
for (String key : parameter.getExtensions().keySet())
parameterObject.addEx(new Extension(key, parameter.getExtensions().get(key)));
}
}
return parameterObject;
}
public static RequestBodyOb RequestBodyOb.parseRequestBody(RequestBody requestBody) {
RequestBodyObject requestBodyObject = new RequestBodyObject();
if (requestBody.get$ref() != null) {
RequestBodyReference r = new RequestBodyReference();
r.setRef(requestBody.get$ref());
/* 3.1.0 features
if (requestBody.getSummary() != null) ...
if (requestBody.getDescription() != null) ...
*/
return r;
} else {
if (requestBody.getContent() != null) {
for (String key : requestBody.getContent().keySet())
requestBodyObject.addC(new ContentTuple(key, MediaTypeObject.parseMediaType(requestBody.getContent().get(key))));
}
if (requestBody.getDescription() != null)
requestBodyObject.setDescription(requestBody.getDescription());
if (requestBody.getRequired() != null)
requestBodyObject.setRequired(requestBody.getRequired());
if (requestBody.getExtensions().size() != 0) {
for (String key : requestBody.getExtensions().keySet())
requestBodyObject.addEx(new Extension(key, requestBody.getExtensions().get(key)));
}
}
return requestBodyObject;
}
public static MediaTypeObject MediaTypeObject.parseMediaType(MediaType mediaType) {
MediaTypeObject mediaTypeObject = new MediaTypeObject();
if (mediaType.getSchema() != null)
mediaTypeObject.set_impl_s(SchemaObject.parseSchema(mediaType.getSchema()));
if (mediaType.getExample() != null)
mediaTypeObject.setExample(mediaType.getExample());
if (mediaType.getExamples().size() != 0) {
for (String key : mediaType.getExamples().keySet())
mediaTypeObject.addE(new ExampleTuple(key, ExampleObject.parseExample(mediaType.getExamples().get(key))));
}
if (mediaType.getEncoding().size() != 0) {
for (String key : mediaType.getEncoding().keySet())
mediaTypeObject.addEn(new EncodingTuple(key, EncodingObject.parseEncoding(mediaType.getEncoding().get(key))));
}
if (mediaType.getExtensions().size() != 0) {
for (String key : mediaType.getExtensions().keySet())
mediaTypeObject.addEx(new Extension(key, mediaType.getExtensions().get(key)));
}
return mediaTypeObject;
}
public static EncodingObject EncodingObject.parseEncoding(Encoding encodingProperty) {
EncodingObject encodingObject = new EncodingObject();
if (encodingProperty.getContentType() != null)
encodingObject.setContentType(encodingProperty.getContentType());
if (encodingProperty.getHeaders() != null) {
for (String key : encodingProperty.getHeaders().keySet())
encodingObject.addH(new HeaderTuple(key, HeaderObject.parseHeader(encodingProperty.getHeaders().get(key))));
}
if (encodingProperty.getStyle() != null)
encodingObject.setStyle(encodingProperty.getStyle().toString());
if (encodingProperty.getExplode() != null)
encodingObject.setExplode(encodingProperty.getExplode());
if (encodingProperty.getAllowReserved() != null)
encodingObject.setAllowReserved(encodingProperty.getAllowReserved());
if (encodingProperty.getExtensions() != null) {
for (String key : encodingProperty.getExtensions().keySet())
encodingObject.addEx(new Extension(key, encodingProperty.getExtensions().get(key)));
}
return encodingObject;
}
public static ResponseOb ResponseOb.parseResponse(ApiResponse response) {
ResponseObject responseObject = new ResponseObject();
if (response.get$ref() != null) {
ResponseReference r = new ResponseReference();
r.setRef(response.get$ref());
/* 3.1.0 features
if (response.getSummary() != null) ...
if (response.getDescription() != null) ...
*/
return r;
} else {
if (response.getDescription() != null)
responseObject.setDescription(response.getDescription());
if (response.getHeaders().size() != 0) {
for (String key : response.getHeaders().keySet())
responseObject.addH(new HeaderTuple(key, HeaderObject.parseHeader(response.getHeaders().get(key))));
}
if (response.getContent().size() != 0) {
for (String key : response.getContent().keySet())
responseObject.addC(new ContentTuple(key, MediaTypeObject.parseMediaType(response.getContent().get(key))));
}
if (response.getLinks().size() != 0) {
for (String key : response.getLinks().keySet())
responseObject.addL(new LinkTuple(key, LinkOb.parseLink(response.getLinks().get(key))));
}
if (response.getExtensions().size() != 0) {
for (String key : response.getExtensions().keySet())
responseObject.addEx(new Extension(key, response.getExtensions().get(key)));
}
}
return responseObject;
}
public static CallbackOb CallbackOb.parseCallback(Callback callback) {
CallbackObject callbackObject = new CallbackObject();
if (callback.get$ref() != null) {
CallbackReference c = new CallbackReference();
c.setRef(callback.get$ref());
/* 3.1.0 features
if (callback.getSummary() != null) ...
if (callback.getDescription() != null) ...
*/
return c;
} else {
if (callback.size() != 0) {
for (String key : callback.keySet())
callbackObject.addE(new Expression(key, PathItemObject.parsePath(callback.get(key))));
}
if (callback.getExtensions().size() != 0) {
for (String key : callback.getExtensions().keySet())
callbackObject.addEx(new Extension(key, callback.getExtensions().get(key)));
}
}
return callbackObject;
}
public static ExampleObject ExampleObject.parseExample(Example example){
ExampleObject exampleObject = new ExampleObject();
if (example.getSummary() != null)
exampleObject.setSummary(example.getSummary());
if (example.getDescription() != null)
exampleObject.setDescription(example.getDescription());
if (example.getValue() != null)
exampleObject.setValue(example.getValue());
if (example.getExternalValue() != null)
exampleObject.setExternalValue(example.getExternalValue());
if (example.getExtensions().size() != 0) {
for (String key : example.getExtensions().keySet())
exampleObject.addEx(new Extension(key, example.getExtensions().get(key)));
}
return exampleObject;
}
public static LinkOb LinkOb.parseLink(Link link) {
LinkObject linkObject = new LinkObject();
if (link.get$ref() != null) {
LinkReference l = new LinkReference();
l.setRef(link.get$ref());
/* 3.1.0 features
if (link.getSummary() != null) ...
if (link.getDescription() != null) ...
*/
return l;
} else {
if (link.getOperationRef() != null)
linkObject.setOperationRef(link.getOperationRef());
if (link.getOperationId() != null)
linkObject.setOperationID(link.getOperationId());
if (link.getParameters().size() != 0) {
for (String key : link.getParameters().keySet())
linkObject.addL(new LinkParameterTuple(key, link.getParameters().get(key)));
}
if (link.getDescription() != null)
linkObject.setDescription(link.getDescription());
if (link.getServer() != null)
linkObject.set_impl_s(ServerObject.parseServer(link.getServer()));
if (link.getExtensions().size() != 0) {
for (String key : link.getExtensions().keySet())
linkObject.addEx(new Extension(key, link.getExtensions().get(key)));
}
}
return linkObject;
}
public static HeaderOb HeaderOb.parseHeader(Header header) {
HeaderObject headerObject = new HeaderObject();
if (header.get$ref() != null) {
HeaderReference h = new HeaderReference();
h.setRef(header.get$ref());
/* 3.1.0 features
if (header.getSummary() != null) ...
if (header.getDescription() != null) ...
*/
return h;
} else {
if (header.getRequired() != null)
headerObject.setRequired(header.getRequired());
if (header.getDescription() != null)
headerObject.setDescription(header.getDescription());
if (header.getDeprecated() != null)
headerObject.setDeprecatedBoolean(header.getDeprecated());
if (header.getStyle() != null)
headerObject.setStyle(header.getStyle().toString());
if (header.getExplode() != null)
headerObject.setExplode(header.getExplode());
if (header.getExample() != null)
headerObject.setExample(header.getExample());
if (header.getExamples().size() != 0) {
for (String key : header.getExamples().keySet())
headerObject.addE(new ExampleTuple(key, ExampleObject.parseExample(header.getExamples().get(key))));
}
if (header.getContent().size() != 0) {
for (String key : header.getContent().keySet())
headerObject.addC(new ContentTuple(key, MediaTypeObject.parseMediaType(header.getContent().get(key))));
}
if (header.getSchema() != null)
headerObject.set_impl_s(SchemaOb.parseSchema(header.getSchema()));
if (header.getExtensions() != null) {
for (String key : header.getExtensions().keySet())
headerObject.addEx(new Extension(key, header.getExtensions().get(key)));
}
}
return headerObject;
}
public static TagObject TagObject.parseTag(io.swagger.v3.oas.models.tags.Tag tag){
TagObject tagObject = new TagObject();
tagObject.setName(tag.getName());
if (tag.getDescription() != null)
tagObject.setDescription(tag.getDescription());
if (tag.getExternalDocs() != null)
tagObject.set_impl_e(ExternalDocObject.parseExternalDocs(tag.getExternalDocs()));
if (tag.getExtensions().size() != 0) {
for (String key : tag.getExtensions().keySet())
tagObject.addEx(new Extension(key, tag.getExtensions().get(key)));
}
return tagObject;
}
public static SchemaOb SchemaOb.parseSchema (Schema<?> schema) {
SchemaObject schemaObject = new SchemaObject();
if (schema.get$ref() != null) {
SchemaReference s = new SchemaReference();
s.setRef(schema.get$ref());
/* 3.1.0 features
if (schema.getSummary() != null) ...
if (schema.getDescription() != null) ...
*/
return s;
} else {
if (schema.getAdditionalProperties() != null)
schemaObject.setAdditionalProperties(schema.getAdditionalProperties());
if (schema.getDefault() != null)
schemaObject.setDefaultValue(schema.getDefault());
if (schema.getDescription() != null)
schemaObject.setDescription(schema.getDescription());
if (schema.getDeprecated() != null)
schemaObject.setDeprecatedBoolean(schema.getDeprecated());
if (schema.getDiscriminator() != null)
schemaObject.setD(DiscriminatorObject.parseDiscriminator(schema.getDiscriminator()));
if (schema.getEnum() != null) {
for (Object o : schema.getEnum()) {
EnumObj enumObj = new EnumObj();
enumObj.setEnumOb(o);
schemaObject.addE(enumObj);
}
}
// in 3.1.0, there are multiple examples
if (schema.getExample() != null)
schemaObject.addEl(new ExampleElement(schema.getExample()));
/* in 3.1.0, types are Number instead of Boolean
if (schema.getExclusiveMaximum() != null)
schemaObject.setExclusiveMaximum(schema.getExclusiveMaximum());
if (schema.getExclusiveMinimum() != null)
schemaObject.setExclusiveMinimum(schema.getExclusiveMinimum());
*/
if (schema.getExternalDocs() != null)
schemaObject.setExt(ExternalDocObject.parseExternalDocs(schema.getExternalDocs()));
if (schema.getFormat() != null)
schemaObject.setFormat(schema.getFormat());
if (schema.getMaximum() != null)
schemaObject.setMaximum(schema.getMaximum());
if (schema.getMinimum() != null)
schemaObject.setMinimum(schema.getMinimum());
if (schema.getMaxItems() != null)
schemaObject.setMaxItems(schema.getMaxItems());
if (schema.getMinItems() != null)
schemaObject.setMinItems(schema.getMinItems());
if (schema.getMaxLength() != null)
schemaObject.setMaxLength(schema.getMaxLength());
if (schema.getMinLength() != null)
schemaObject.setMinLength(schema.getMinLength());
if (schema.getMaxProperties() != null)
schemaObject.setMaxProperties(schema.getMaxProperties());
if (schema.getMinProperties() != null)
schemaObject.setMinProperties(schema.getMinProperties());
if (schema.getMultipleOf() != null)
schemaObject.setMultipleOf(schema.getMultipleOf());
if (schema.getNot() != null) {
NotSchema notSchema = new NotSchema();
notSchema.set_impl_s(parseSchema(schema.getNot()));
schemaObject.set_impl_n(notSchema);
}
if (schema.getPattern() != null)
schemaObject.setPattern(schema.getPattern());
if (schema.getProperties().size() != 0) {
for (String key : schema.getProperties().keySet()) {
PropertyItem propertyItem = new PropertyItem();
schemaObject.addP(new PropertyItem(key, parseSchema(schema.getProperties().get(key))));
}
}
if (schema.getRequired().size() != 0) {
for (String s : schema.getRequired()) {
RequiredField requiredField = new RequiredField();
requiredField.setValue(s);
schemaObject.addR(requiredField);
}
}
/* Schemas not supported (maybe supported in 3.1.0)
if (schema.getItemsSchema() != null) {
ItemsSchema itemsSchema = new ItemsSchema();
itemsSchema.setSchemaOb(parseSchema(schema.getItemsSchema(), context, map));
schemaObject.setItemsSchema(itemsSchema);
}
if (schema.getAllOfSchemas() != null) {
for (org.openapi4j.parser.model.v3.Schema schemaItem : schema.getAllOfSchemas()) {
AllOfSchema allOfSchema = new AllOfSchema();
allOfSchema.setSchemaOb(parseSchema(schemaItem, context, map));
schemaObject.addAllOfSchema(allOfSchema);
}
}
if (schema.getAnyOfSchemas() != null) {
for (org.openapi4j.parser.model.v3.Schema schemaItem : schema.getAnyOfSchemas()) {
AnyOfSchema anyOfSchema = new AnyOfSchema();
anyOfSchema.setSchemaOb(parseSchema(schemaItem, context, map));
schemaObject.addAnyOfSchema(anyOfSchema);
}
}
if (schema.getOneOfSchemas() != null) {
for (org.openapi4j.parser.model.v3.Schema schemaItem : schema.getOneOfSchemas()) {
OneOfSchema oneOfSchema = new OneOfSchema();
oneOfSchema.setSchemaOb(parseSchema(schemaItem, context, map));
schemaObject.addOneOfSchema(oneOfSchema);
}
}
*/
if (schema.getReadOnly() != null)
schemaObject.setReadOnly(schema.getReadOnly());
if (schema.getWriteOnly() != null)
schemaObject.setWriteOnly(schema.getWriteOnly());
if (schema.getType() != null)
schemaObject.setType(schema.getType());
if (schema.getTitle() != null)
schemaObject.setTitle(schema.getTitle());
if (schema.getUniqueItems() != null)
schemaObject.setUniqueItems(schema.getUniqueItems());
if (schema.getXml() != null)
schemaObject.setX(XmlObject.parseXml(schema.getXml()));
if (schema.getExtensions().size() != 0) {
for (String key : schema.getExtensions().keySet())
schemaObject.addEx(new Extension(key, schema.getExtensions().get(key)));
}
}
return schemaObject;
}
public static DiscriminatorObject DiscriminatorObject.parseDiscriminator (Discriminator discriminator) {
DiscriminatorObject discriminatorObject = new DiscriminatorObject();
if (discriminator.getPropertyName() != null)
discriminatorObject.setPropertyName(discriminator.getPropertyName());
if (discriminator.getMapping() != null) {
MappingTuple mapping = new MappingTuple();
for (String key : discriminator.getMapping().keySet()) {
mapping.setKey(key);
mapping.setValue(discriminator.getMapping().get(key));
discriminatorObject.addM(mapping);
}
}
return discriminatorObject;
}
public static XmlObject XmlObject.parseXml (XML xml) {
XmlObject xmlObject = new XmlObject();
if (xml.getName() != null)
xmlObject.setName(xml.getName());
if (xml.getNamespace() != null)
xmlObject.setNamespace(xml.getNamespace());
if (xml.getPrefix() != null)
xmlObject.setPrefix(xml.getPrefix());
if (xml.getAttribute() != null)
xmlObject.setAttribute(xml.getAttribute());
if (xml.getWrapped() != null)
xmlObject.setWrapped(xml.getWrapped());
if (xml.getExtensions() != null) {
for (String key : xml.getExtensions().keySet())
xmlObject.addEx(new Extension(key, xml.getExtensions().get(key)));
}
return xmlObject;
}
public static SecuritySchemeOb SecuritySchemeOb.parseSecurityScheme(SecurityScheme securityScheme){
SecuritySchemeObject securitySchemeObject = new SecuritySchemeObject();
if(securityScheme.get$ref() != null){
SecuritySchemeReference r = new SecuritySchemeReference();
r.setRef(securityScheme.get$ref());
/* 3.1.0 features
if (securityScheme.getSummary() != null) ...
if (securityScheme.getDescription() != null) ...
*/
return r;
} else {
if (securityScheme.getType() != null)
securitySchemeObject.setType(securityScheme.getType().toString());
if (securityScheme.getName() != null)
securitySchemeObject.setName(securityScheme.getName());
if (securityScheme.getIn() != null)
securitySchemeObject.setIn(securityScheme.getIn().toString());
if (securityScheme.getScheme() != null)
securitySchemeObject.setScheme(securityScheme.getScheme());
if (securityScheme.getOpenIdConnectUrl() != null)
securitySchemeObject.setOpenIdConnectUrl(securityScheme.getOpenIdConnectUrl());
if (securityScheme.getFlows() != null)
securitySchemeObject.setO(OAuthFlowsObject.parseOAuthFlows(securityScheme.getFlows()));
if (securityScheme.getDescription() != null)
securitySchemeObject.setDescription(securityScheme.getDescription());
if (securityScheme.getBearerFormat() != null)
securitySchemeObject.setBearerFormat(securityScheme.getBearerFormat());
if (securityScheme.getExtensions() != null) {
for (String key : securityScheme.getExtensions().keySet())
securitySchemeObject.addEx(new Extension(key, securityScheme.getExtensions().get(key)));
}
}
return securitySchemeObject;
}
public static OAuthFlowsObject OAuthFlowsObject.parseOAuthFlows(OAuthFlows oAuthFlows){
OAuthFlowsObject oAuthFlowsObject = new OAuthFlowsObject();
Implicit implicit = new Implicit();
Password password = new Password();
ClientCredentials clientCredentials = new ClientCredentials();
AuthorizationCode authorizationCode = new AuthorizationCode();
if (oAuthFlows.getImplicit() != null) {
implicit.set_impl_o(OAuthFlowObject.parseOAuthFlow(oAuthFlows.getImplicit()));
oAuthFlowsObject.set_impl_i(implicit);
}
if (oAuthFlows.getPassword() != null) {
password.set_impl_o(OAuthFlowObject.parseOAuthFlow(oAuthFlows.getPassword()));
oAuthFlowsObject.set_impl_p(password);
}
if (oAuthFlows.getClientCredentials() != null) {
clientCredentials.set_impl_o(OAuthFlowObject.parseOAuthFlow(oAuthFlows.getClientCredentials()));
oAuthFlowsObject.set_impl_c(clientCredentials);
}
if (oAuthFlows.getAuthorizationCode() != null) {
authorizationCode.set_impl_o(OAuthFlowObject.parseOAuthFlow(oAuthFlows.getAuthorizationCode()));
oAuthFlowsObject.set_impl_a(authorizationCode);
}
if (oAuthFlows.getExtensions() != null) {
for (String key : oAuthFlows.getExtensions().keySet())
oAuthFlowsObject.addEx(new Extension(key, oAuthFlows.getExtensions().get(key)));
}
return oAuthFlowsObject;
}
public static OAuthFlowObject OAuthFlowObject.parseOAuthFlow(OAuthFlow oAuthFlow){
OAuthFlowObject oAuthFlowObject = new OAuthFlowObject();
if (oAuthFlow.getAuthorizationUrl() != null)
oAuthFlowObject.setAuthorizationUrl(oAuthFlow.getAuthorizationUrl());
if (oAuthFlow.getTokenUrl() != null)
oAuthFlowObject.setTokenUrl(oAuthFlow.getTokenUrl());
for (String key : oAuthFlow.getScopes().keySet())
oAuthFlowObject.addS(new ScopesTuple(key, oAuthFlow.getScopes().get(key)));
if (oAuthFlow.getRefreshUrl() != null)
oAuthFlowObject.setRefreshUrl(oAuthFlow.getRefreshUrl());
if (oAuthFlow.getExtensions() != null) {
for (String key : oAuthFlow.getExtensions().keySet())
oAuthFlowObject.addEx(new Extension(key, oAuthFlow.getExtensions().get(key)));
}
return oAuthFlowObject;
}
public static SecurityRequirementObject SecurityRequirementObject.parseSecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement securityRequirement){
SecurityRequirementObject securityRequirementObject = new SecurityRequirementObject();
if (securityRequirement != null) {
for (String key : securityRequirement.keySet()) {
List<SecurityRequirementValue> values = new ArrayList<>();
for (String v : securityRequirement.get(key))
values.add(new SecurityRequirementValue(v));
securityRequirementObject.addT(new SecurityRequirementTuple(key, values));
}
}
return securityRequirementObject;
}
}
Loading