Java Code Examples for io.swagger.v3.oas.models.Components#getSchemas()
The following examples show how to use
io.swagger.v3.oas.models.Components#getSchemas() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefPointer.java From openapi-diff with Apache License 2.0 | 6 votes |
private Map<String, T> getMap(Components components) { switch (refType) { case REQUEST_BODIES: return (Map<String, T>) components.getRequestBodies(); case RESPONSES: return (Map<String, T>) components.getResponses(); case PARAMETERS: return (Map<String, T>) components.getParameters(); case SCHEMAS: return (Map<String, T>) components.getSchemas(); case HEADERS: return (Map<String, T>) components.getHeaders(); case SECURITY_SCHEMES: return (Map<String, T>) components.getSecuritySchemes(); default: throw new IllegalArgumentException("Not mapped for refType: " + refType); } }
Example 2
Source File: OpenAPIParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssue768() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIParser().readLocation("issue768-main.yaml", null, options); assertNotNull(result); OpenAPI openAPI = result.getOpenAPI(); assertNotNull(openAPI); Components components = openAPI.getComponents(); assertNotNull(components); Map<String, Schema> schemas = components.getSchemas(); assertNotNull(schemas); assertEquals(schemas.size(), 1); }
Example 3
Source File: SpringDocConfiguration.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Properties resolver for schema open api customiser. * * @param propertyResolverUtils the property resolver utils * @param openAPIBuilder the open api builder * @return the open api customiser */ @Bean @ConditionalOnProperty(SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES) @Lazy(false) OpenApiCustomiser propertiesResolverForSchema(PropertyResolverUtils propertyResolverUtils, OpenAPIBuilder openAPIBuilder) { return openApi -> { Components components = openApi.getComponents(); Map<String, Schema> schemas = components.getSchemas(); schemas.values().forEach(schema -> openAPIBuilder.resolveProperties(schema, propertyResolverUtils)); }; }
Example 4
Source File: SpringDocAnnotationsUtils.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Extract schema schema. * * @param components the components * @param returnType the return type * @param jsonView the json view * @param annotations the annotations * @return the schema */ public static Schema extractSchema(Components components, Type returnType, JsonView jsonView, Annotation[] annotations) { Schema schemaN = null; ResolvedSchema resolvedSchema = null; try { resolvedSchema = ModelConverters.getInstance() .resolveAsResolvedSchema( new AnnotatedType(returnType).resolveAsRef(true).jsonViewAnnotation(jsonView).ctxAnnotations(annotations)); } catch (Exception e) { LOGGER.warn(Constants.GRACEFUL_EXCEPTION_OCCURRED, e); return null; } if (resolvedSchema.schema != null) { schemaN = resolvedSchema.schema; Map<String, Schema> schemaMap = resolvedSchema.referencedSchemas; if (schemaMap != null) { for (Map.Entry<String, Schema> entry : schemaMap.entrySet()) { Map<String, Schema> componentSchemas = components.getSchemas(); if (componentSchemas == null) { componentSchemas = new LinkedHashMap<>(); componentSchemas.put(entry.getKey(), entry.getValue()); } else if (!componentSchemas.containsKey(entry.getKey())) { componentSchemas.put(entry.getKey(), entry.getValue()); } components.setSchemas(componentSchemas); } } } return schemaN; }
Example 5
Source File: OpenAPIParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue749() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIParser().readLocation("issue749-main.yaml", null, options); assertNotNull(result); OpenAPI openAPI = result.getOpenAPI(); assertNotNull(openAPI); Components components = openAPI.getComponents(); assertNotNull(components); PathItem pathItem = openAPI.getPaths().get("/some/ping"); assertNotNull(pathItem); List<Parameter> parameters = pathItem.getGet().getParameters(); assertNotNull(parameters); assertEquals(parameters.size(), 1); assertEquals(parameters.get(0).getName(), "i"); assertNotNull(parameters.get(0).getSchema()); assertEquals(parameters.get(0).getSchema().get$ref(), "#/components/schemas/SomeId"); Map<String, Schema> schemas = components.getSchemas(); assertNotNull(schemas); assertEquals(schemas.size(), 1); assertNotNull(schemas.get("SomeId")); }
Example 6
Source File: ComponentsSchemasKeysValidator.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
@Override protected Map<String, ?> getMapProperty(Components components) { return components.getSchemas(); }
Example 7
Source File: ComponentsSchemasValuesValidator.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
@Override protected Map<String, Schema> getMapProperty(Components components) { return components.getSchemas(); }
Example 8
Source File: ComponentsTransformer.java From swagger-brake with Apache License 2.0 | 4 votes |
@Override public SchemaStore transform(Components from) { return new SchemaStore(from.getSchemas()); }
Example 9
Source File: ResolverFully.java From swagger-parser with Apache License 2.0 | 4 votes |
public void resolveFully(OpenAPI openAPI) { Components components = openAPI.getComponents(); if (components != null && components.getRequestBodies() != null) { requestBodies = components.getRequestBodies(); if (requestBodies == null) { requestBodies = new HashMap<>(); } } if (components != null && components.getSchemas() != null) { schemas = components.getSchemas(); if (schemas == null) { schemas = new HashMap<>(); } } if (components != null && components.getExamples() != null) { examples = components.getExamples(); if (examples == null) { examples = new HashMap<>(); } } if (components != null && components.getHeaders() != null) { headers = components.getHeaders(); if (headers == null) { headers = new HashMap<>(); } } if (components != null && components.getParameters() != null) { parameters = components.getParameters(); if (parameters == null) { parameters = new HashMap<>(); } } if (components != null && components.getLinks() != null) { links = components.getLinks(); if (links == null) { links = new HashMap<>(); } } Paths paths = openAPI.getPaths(); if(paths != null) { for (String pathname : paths.keySet()) { PathItem pathItem = paths.get(pathname); resolvePath(pathItem); } } }