private void correctConsumes() { List<String> consumes = swagger.getConsumes(); if (consumes == null || consumes.isEmpty()) { consumes = Arrays.asList(MediaType.APPLICATION_JSON); swagger.setConsumes(consumes); } }
/** * Builds the overview MarkupDocument. * * @return the overview MarkupDocument */ @Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, OverviewDocument.Parameters params) { Swagger swagger = params.swagger; Info info = swagger.getInfo(); buildDocumentTitle(markupDocBuilder, info.getTitle()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder)); buildOverviewTitle(markupDocBuilder, labels.getLabel(Labels.OVERVIEW)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder)); buildDescriptionParagraph(markupDocBuilder, info.getDescription()); buildVersionInfoSection(markupDocBuilder, info); buildContactInfoSection(markupDocBuilder, info.getContact()); buildLicenseInfoSection(markupDocBuilder, info); buildUriSchemeSection(markupDocBuilder, swagger); buildTagsSection(markupDocBuilder, swagger.getTags()); buildConsumesSection(markupDocBuilder, swagger.getConsumes()); buildProducesSection(markupDocBuilder, swagger.getProduces()); buildExternalDocsSection(markupDocBuilder, swagger.getExternalDocs()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder)); return markupDocBuilder; }
private void processConsumes(Api api, Swagger swagger) { List<String> validConsumesList = getValidStringList(api.consumes()); if (isBlank(swagger.getConsumes()) && !validConsumesList.isEmpty()) { swagger.setConsumes(validConsumesList); } }
private void correctConsumes() { List<String> consumes = swagger.getConsumes(); if (consumes == null || consumes.isEmpty()) { consumes = Arrays.asList(MediaType.APPLICATION_JSON); swagger.setConsumes(consumes); } }
private List<String> buildHeaders( Swagger swagger, Map.Entry<String, Path> path, Map.Entry<HttpMethod, Operation> operation ) { List<String> headers = new ArrayList<>(); headers.add( operation.getKey().toString() + " " + swagger.getBasePath() + path.getKey() + " HTTP/1.1"); headers.add("Host: " + swagger.getHost().split(":")[0]); if (CollectionUtils.isNotEmpty(operation.getValue().getProduces())) { headers.add("Accept: " + String.join(",", operation.getValue().getProduces())); } else if (CollectionUtils.isNotEmpty(swagger.getProduces())) { headers.add("Accept: " + String.join(",", swagger.getProduces())); } if (CollectionUtils.isNotEmpty(operation.getValue().getConsumes())) { headers.add("Content-Type: " + String.join(",", operation.getValue().getConsumes())); } else if (CollectionUtils.isNotEmpty(swagger.getConsumes())) { headers.add("Content-Type: " + String.join(",", swagger.getConsumes())); } return headers; }
List<String> getExpectedConsumes(Operation op) { return getListWithFallback(op.getConsumes(), expected.getConsumes()); }
List<String> getActualConsumes(Operation op) { return getListWithFallback(op.getConsumes(), actual.getConsumes()); }
private void processConsumes(Api api, Swagger swagger) { List<String> validConsumesList = getValidStringList(api.consumes()); if (isBlank(swagger.getConsumes()) && !validConsumesList.isEmpty()) { swagger.setConsumes(validConsumesList); } }
@Override public DataShape createShapeFromRequest(final ObjectNode json, final Swagger swagger, final Operation operation) { if (supports(APPLICATION_JSON, swagger.getConsumes(), operation.getConsumes())) { return JSON.createShapeFromRequest(json, swagger, operation); } else if (supports(APPLICATION_XML, swagger.getConsumes(), operation.getConsumes())) { return XML.createShapeFromRequest(json, swagger, operation); } else { // most likely a body-less request, i.e. only with parameters, we'll // use JSON to define those parameters return JSON.createShapeFromRequest(json, swagger, operation); } }
@Override public DataShape createShapeFromRequest(final ObjectNode json, final Swagger swagger, final Operation operation) { if (supports(APPLICATION_JSON, swagger.getConsumes(), operation.getConsumes())) { return JSON.createShapeFromRequest(json, swagger, operation); } else if (supports(APPLICATION_XML, swagger.getConsumes(), operation.getConsumes())) { return XML.createShapeFromRequest(json, swagger, operation); } else { // most likely a body-less request, i.e. only with parameters, we'll // use JSON to define those parameters return JSON.createShapeFromRequest(json, swagger, operation); } }
@Override public DataShape createShapeFromRequest(final String specification, final Swagger swagger, final Operation operation) { if (supports(APPLICATION_JSON, swagger.getConsumes(), operation.getConsumes())) { return JSON.createShapeFromRequest(specification, swagger, operation); } else if (supports(APPLICATION_XML, swagger.getConsumes(), operation.getConsumes())) { return XML.createShapeFromRequest(specification, swagger, operation); } else { // most likely a body-less request, i.e. only with parameters, we'll // use JSON to define those parameters return JSON.createShapeFromRequest(specification, swagger, operation); } }
final String determinedProducers = determineOption(swagger.getConsumes(), operation.getConsumes(), component.getProduces(), produces);
@Override public void operation(HttpMethod httpMethod, Operation operation) { if (operation.getConsumes() == null) { operation.setConsumes(model.getConsumes()); } if (operation.getProduces() == null) { operation.setProduces(model.getProduces()); } } });
consumes.addAll(getOrEmpty(spec.getConsumes())); produces.addAll(getOrEmpty(spec.getProduces())); childSchemes.addAll(getOrEmpty(spec.getSchemes()));
Operation operation = operations.get(method); if (isEmpty(operation.getConsumes())) operation.setConsumes(swagger.getConsumes()); if (isEmpty(operation.getProduces())) operation.setProduces(swagger.getProduces());
String consumes = getTypes(nvl(operation.getConsumes(), swagger.getConsumes()), getPreferredConsumes()); String name = operation.getOperationId(); if (name == null) {
logger.info("Base path: " + swagger.getBasePath()); logger.info("Schemes: " + swagger.getSchemes()); logger.info("Consumes: " + swagger.getConsumes()); logger.info("Produces: " + swagger.getProduces()); logger.info("Paths: " + swagger.getPaths());
private Swagger createSwagger(final Set<Class<?>> classes,final URL url){ Swagger swagger = new Reader(new Swagger()).read(classes); Info info = getSwaggerInfo(swagger); if(info!=null)swagger.setInfo(info); Map<String, SecuritySchemeDefinition> securityDefinitions = getSecurityDefinitions(swagger); if(securityDefinitions!=null)swagger.setSecurityDefinitions(securityDefinitions); String consumes = whiteLabel.getProperty(CONSUMES, null); if(anyIsSet(consumes))swagger.setConsumes(toList(swagger.getConsumes(),consumes)); String produces = whiteLabel.getProperty(PRODUCES, null); if(anyIsSet(produces))swagger.setProduces(toList(swagger.getProduces(),produces)); String basePath = whiteLabel.getProperty(BASE_PATH, getBasePath(swagger.getBasePath(), url)); if(anyIsSet(basePath))swagger.setBasePath(basePath); String schemes = whiteLabel.getProperty(SCHEMES, url.getProtocol().toUpperCase()); if(anyIsSet(schemes))swagger.setSchemes(toSchemeList(swagger.getSchemes(),schemes)); String host = whiteLabel.getProperty(HOST, url.getHost() + DOUBLE_POINT + url.getPort()); if(anyIsSet(host))swagger.setHost(host); String tags = whiteLabel.getProperty(TAGS, null); if(anyIsSet(tags))swagger.setTags(toTagList(swagger.getTags(),tags)); return swagger; }
@Override public void swagger(Swagger swagger) { swagger.setSchemes(fillList(swagger.getSchemes())); swagger.setConsumes(fillList(swagger.getConsumes())); swagger.setProduces(fillList(swagger.getProduces())); swagger.setPaths(fillMap(swagger.getPaths())); swagger.setDefinitions(fillMap(swagger.getDefinitions())); swagger.setParameters(fillMap(swagger.getParameters())); swagger.setResponses(fillMap(swagger.getResponses())); swagger.setSecurityDefinitions(fillMap(swagger.getSecurityDefinitions())); swagger.setSecurity(fillList(swagger.getSecurity())); swagger.setTags(fillList(swagger.getTags())); }
/** * Builds the overview MarkupDocument. * * @return the overview MarkupDocument */ @Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, OverviewDocument.Parameters params) { Swagger swagger = params.swagger; Info info = swagger.getInfo(); buildDocumentTitle(markupDocBuilder, info.getTitle()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder)); buildOverviewTitle(markupDocBuilder, labels.getLabel(Labels.OVERVIEW)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder)); buildDescriptionParagraph(markupDocBuilder, info.getDescription()); buildVersionInfoSection(markupDocBuilder, info); buildContactInfoSection(markupDocBuilder, info.getContact()); buildLicenseInfoSection(markupDocBuilder, info); buildUriSchemeSection(markupDocBuilder, swagger); buildTagsSection(markupDocBuilder, swagger.getTags()); buildConsumesSection(markupDocBuilder, swagger.getConsumes()); buildProducesSection(markupDocBuilder, swagger.getProduces()); buildExternalDocsSection(markupDocBuilder, swagger.getExternalDocs()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder)); return markupDocBuilder; }