本文整理汇总了Java中io.swagger.models.Model类的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于io.swagger.models包,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import io.swagger.models.Model; //导入依赖的package包/类
public Result validate(BodyParameter bodyParam, JSONObject body, boolean strict) throws ValidationException {
Result result = new Result();
if (body == null) {
if (bodyParam.getRequired())
result.also(Status.BAD_REQUEST, "Missing required body parameter: " + bodyParam.getName());
}
else {
Model model = bodyParam.getSchema();
if (model instanceof RefModel) {
Model bodyModel = swaggerRequest.getDefinitions().get(((RefModel)model).getSimpleRef());
if (bodyModel != null)
result.also(validate(body, bodyModel, "", strict));
}
}
return result;
}
示例2: paramBody
import io.swagger.models.Model; //导入依赖的package包/类
/**
* Build BodyParameter for the Route parameter of type body.
*/
private BodyParameter paramBody(List<RequestRouter.Parameter> routeParams, Route route) {
BodyParameter bodyParam = new BodyParameter();
bodyParam.setRequired(false);
Model model = new ModelImpl();
if (routeParams != null) {
Map<String, Property> properties = new HashMap<>(routeParams.size());
routeParams.stream().forEach((p) -> {
StringProperty stringProperty = new StringProperty();
stringProperty.setName(p.name);
stringProperty
.setDescription(isBlank(p.description) ? route.description : p.description);
stringProperty.setDefault(p.value);
stringProperty.setRequired(p.required);
stringProperty.setType(StringProperty.TYPE);
properties.put(p.name, stringProperty);
});
model.setProperties(properties);
}
bodyParam.setSchema(model);
return bodyParam;
}
示例3: processUris
import io.swagger.models.Model; //导入依赖的package包/类
private void processUris(final Map<String, Path> swagger,
final Map<String, Model> definitionsMap,
final Map<String, SecuritySchemeDefinition> securityDefinitionsMap,
final int i) {
int j = 0;
while (env.containsProperty(String.format("swagger[%d].uris[%d].swagger", i, j))) {
try {
final URL swaggerUrl = env.getProperty(String.format("swagger[%d].uris[%d].swagger", i, j), URL.class);
final Swagger remoteSwagger = io.swagger.util.Json.mapper().readerFor(Swagger.class).readValue(swaggerUrl.openConnection().getInputStream());
processPaths(swagger, definitionsMap, securityDefinitionsMap, remoteSwagger, i, j);
++j;
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}
}
示例4: parse
import io.swagger.models.Model; //导入依赖的package包/类
public static Swagger parse(String requestUrl, Collection<UrlMapper> collection) {
Swagger swagger = parseCommon(requestUrl, null);
List<Tag> tags = new ArrayList<Tag>();
Map<String, Path> paths = new HashMap<String, Path>();
Map<String, Model> models = new HashMap<String, Model>();
for (UrlMapper urlMapper : collection) {
if (urlMapper != null) {
Swagger p_swagger = parse(requestUrl, urlMapper);
if (p_swagger != null) {
if (p_swagger != null) {
tags.addAll(p_swagger.getTags());
paths.putAll(p_swagger.getPaths());
models.putAll(p_swagger.getDefinitions());
}
}
}
}
swagger.setTags(tags);
swagger.setPaths(paths);
swagger.setDefinitions(models);
return swagger;
}
示例5: mapGraphValue
import io.swagger.models.Model; //导入依赖的package包/类
@Override
public Object mapGraphValue(@NonNull RefProperty schema,
@NonNull GraphEntityContext graphEntityContext,
@NonNull ValueContext valueContext,
@NonNull SchemaMapperAdapter schemaMapperAdapter) {
Model refModel = graphEntityContext.getSwaggerDefinitions().get(schema.getSimpleRef());
if (refModel == null) {
throw new SchemaMapperRuntimeException(String.format(
"Unable to resolve reference to swagger model: '%s'.", schema.getSimpleRef()));
}
Builder<String, Object> builder = ImmutableMap.builder();
refModel.getProperties().forEach((propKey, propValue) -> builder.put(propKey,
Optional.fromNullable(schemaMapperAdapter.mapGraphValue(propValue, graphEntityContext,
valueContext, schemaMapperAdapter))));
return builder.build();
}
示例6: mapGraphValue_ReturnsResults_WhenRefCanBeResolved
import io.swagger.models.Model; //导入依赖的package包/类
@Test
public void mapGraphValue_ReturnsResults_WhenRefCanBeResolved() {
// Arrange
property.set$ref(DUMMY_REF);
Model refModel = new ModelImpl();
refModel.setProperties(ImmutableMap.of(KEY_1, PROPERTY_1, KEY_2, PROPERTY_2));
when(entityBuilderContext.getLdPathExecutor()).thenReturn(ldPathExecutor);
when(entityBuilderContext.getSwaggerDefinitions()).thenReturn(
ImmutableMap.of(property.getSimpleRef(), refModel));
when(ldPathExecutor.ldPathQuery(context, LD_PATH_QUERY)).thenReturn(ImmutableList.of(VALUE_2));
// Act
Map<String, Object> result =
(Map<String, Object>) schemaMapper.mapGraphValue(property, entityBuilderContext,
ValueContext.builder().value(context).build(), schemaMapperAdapter);
// Assert
assertThat(result.keySet(), hasSize(2));
assertEquals(((Optional) result.get(KEY_1)).orNull(), VALUE_1.stringValue());
assertEquals(((Optional) result.get(KEY_2)).orNull(), VALUE_2.intValue());
}
示例7: getDefinationsFromSchemaReference
import io.swagger.models.Model; //导入依赖的package包/类
public HashMap<String, JsonNode> getDefinationsFromSchemaReference(String schemaReference, String schemaName) {
if (schemaDefinationsForReferences == null) {
schemaDefinationsForReferences = new HashMap<>();
}
Model model = swagger.getDefinitions().get(schemaReference);
if(model==null){
System.out.println(schemaReference);
}
if (schemaDefinationsForReferences.containsKey(schemaName)) {
return null;
}
try {
schemaDefinationsForReferences.put(schemaName, jsonMapper.readTree(Json.pretty(model)));
} catch (IOException e) {
e.printStackTrace();
}
getSchemaFromModel(model);
return schemaDefinationsForReferences;
}
示例8: getSchemaFromModel
import io.swagger.models.Model; //导入依赖的package包/类
private void getSchemaFromModel(Model model) {
HashMap<String, Property> references = getAllSchemaReferencesFromModel(model);
references.forEach((modelKey, property) -> {
String simpleRef = null;
Boolean isArray = false;
if (property instanceof RefProperty) {
simpleRef = ((RefProperty) property).getSimpleRef();
} else {
Property items = ((ArrayProperty) property).getItems();
if (items instanceof RefProperty) {
simpleRef = ((RefProperty) items).getSimpleRef();
} else {
return;
}
}
if (simpleRef != null) {
getDefinationsFromSchemaReference(simpleRef, modelKey);
}
});
}
示例9: extractProperties
import io.swagger.models.Model; //导入依赖的package包/类
@Test
public void extractProperties() {
final Map<String, Model> models = ModelConverters.getInstance().readAll(Family.class);
assertEquals(models.size(), 3);
final Model person = models.get("Person");
final Property employer = person.getProperties().get("employer");
assertTrue(employer instanceof ArrayProperty);
final ArrayProperty employerProperty = (ArrayProperty) employer;
final Property items = employerProperty.getItems();
assertTrue(items instanceof RefProperty);
assertEquals(((RefProperty) items).getSimpleRef(), "Employer");
final Property awards = person.getProperties().get("awards");
assertTrue(awards instanceof ArrayProperty);
assertTrue(((ArrayProperty) awards).getItems() instanceof StringProperty);
}
示例10: diff
import io.swagger.models.Model; //导入依赖的package包/类
public ModelDiff diff(Model leftModel, Model rightModel, String parentEl) {
if (null == leftModel && null == rightModel) return this;
Map<String, Property> leftProperties = null == leftModel ? null : leftModel.getProperties();
Map<String, Property> rightProperties = null == rightModel ? null : rightModel.getProperties();
MapKeyDiff<String, Property> propertyDiff = MapKeyDiff.diff(leftProperties, rightProperties);
Map<String, Property> increasedProp = propertyDiff.getIncreased();
Map<String, Property> missingProp = propertyDiff.getMissing();
increased.addAll(convert2ElPropertys(increasedProp, parentEl, false));
missing.addAll(convert2ElPropertys(missingProp, parentEl, true));
List<String> sharedKey = propertyDiff.getSharedKey();
for (String key : sharedKey) {
Property left = leftProperties.get(key);
Property right = rightProperties.get(key);
if (left instanceof RefProperty
&& right instanceof RefProperty) {
String leftRef = ((RefProperty) left).getSimpleRef();
String rightRef = ((RefProperty) right).getSimpleRef();
diff(oldDedinitions.get(leftRef),
newDedinitions.get(rightRef),
null == parentEl ? key : (parentEl + "." + key));
}
}
return this;
}
示例11: asModel
import io.swagger.models.Model; //导入依赖的package包/类
private Model asModel(String typeName, Swagger swagger) {
boolean array = typeName.endsWith("[]");
if (array) {
typeName = typeName.substring(0, typeName.length() - 2);
}
if (swagger.getDefinitions() != null) {
for (Model model : swagger.getDefinitions().values()) {
StringProperty modelType = (StringProperty) model.getVendorExtensions().get("x-className");
if (modelType != null && typeName.equals(modelType.getFormat())) {
return model;
}
}
}
return null;
}
示例12: appendModels
import io.swagger.models.Model; //导入依赖的package包/类
/**
* If the class is annotated with swagger annotations its parsed into a Swagger model representation
* which is added to swagger
*
* @param clazz the class such as pojo with swagger annotation
* @param swagger the swagger model
*/
private void appendModels(Class clazz, Swagger swagger) {
RestModelConverters converters = new RestModelConverters();
final Map<String, Model> models = converters.readClass(clazz);
for (Map.Entry<String, Model> entry : models.entrySet()) {
// favor keeping any existing model that has the vendor extension in the model
boolean oldExt = false;
if (swagger.getDefinitions() != null && swagger.getDefinitions().get(entry.getKey()) != null) {
Model oldModel = swagger.getDefinitions().get(entry.getKey());
if (oldModel.getVendorExtensions() != null) {
oldExt = oldModel.getVendorExtensions().get("x-className") == null;
}
}
if (!oldExt) {
swagger.model(entry.getKey(), entry.getValue());
}
}
}
示例13: readClass
import io.swagger.models.Model; //导入依赖的package包/类
public Map<String, Model> readClass(Class clazz) {
String name = clazz.getName();
Map<String, Model> resolved = super.read(clazz);
if (resolved != null) {
for (Model model : resolved.values()) {
// enrich with the class name of the model
model.getVendorExtensions().put("x-className", new StringProperty(name));
}
// read any extra using read-all
Map<String, Model> extra = super.readAll(clazz);
if (extra != null) {
for (Map.Entry<String, Model> entry : extra.entrySet()) {
if (!resolved.containsKey(entry.getKey())) {
resolved.put(entry.getKey(), entry.getValue());
}
}
}
}
return resolved;
}
示例14: apply
import io.swagger.models.Model; //导入依赖的package包/类
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
String definitionName = params.definitionName;
Model model = params.model;
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEFORE, markupDocBuilder, definitionName, model));
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, definitionName, definitionName);
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEGIN, markupDocBuilder, definitionName, model));
String description = model.getDescription();
if (isNotBlank(description)) {
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
}
inlineDefinitions(markupDocBuilder, typeSection(markupDocBuilder, definitionName, model), definitionName);
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_END, markupDocBuilder, definitionName, model));
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_AFTER, markupDocBuilder, definitionName, model));
return markupDocBuilder;
}
示例15: buildDefinition
import io.swagger.models.Model; //导入依赖的package包/类
/**
* Generate definition files depending on the generation mode
*
* @param definitionName definition name to process
* @param model definition model to process
*/
private void buildDefinition(MarkupDocBuilder markupDocBuilder, String definitionName, Model model) {
if (logger.isDebugEnabled()) {
logger.debug("Definition processed : '{}'", definitionName);
}
if (config.isSeparatedDefinitionsEnabled()) {
MarkupDocBuilder defDocBuilder = copyMarkupDocBuilder(markupDocBuilder);
applyDefinitionComponent(defDocBuilder, definitionName, model);
Path definitionFile = context.getOutputPath().resolve(definitionDocumentNameResolver.apply(definitionName));
defDocBuilder.writeToFileWithoutExtension(definitionFile, StandardCharsets.UTF_8);
if (logger.isDebugEnabled()) {
logger.debug("Separate definition file produced : '{}'", definitionFile);
}
definitionRef(markupDocBuilder, definitionName);
} else {
applyDefinitionComponent(markupDocBuilder, definitionName, model);
}
}