Search in sources :

Example 1 with EnumModel

use of org.glassfish.hk2.classmodel.reflect.EnumModel in project Payara by payara.

the class SchemaImpl method createInstance.

public static SchemaImpl createInstance(AnnotationModel annotation, ApiContext context) {
    SchemaImpl from = new SchemaImpl();
    if (annotation == null) {
        return from;
    }
    // Solve the required attribute before "ref" as it is the only one which doesn't conflict with it.
    final Boolean isRequired = annotation.getValue("required", Boolean.class);
    if (isRequired != null) {
        from.isRequired = isRequired;
    }
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
        return from;
    }
    EnumModel typeEnum = annotation.getValue("type", EnumModel.class);
    if (typeEnum != null) {
        from.setType(SchemaType.valueOf(typeEnum.getValue()));
    }
    final String implementationClass = annotation.getValue("implementation", String.class);
    if (implementationClass != null) {
        setImplementation(from, implementationClass, true, context);
    }
    from.setDefaultValue(annotation.getValue("defaultValue", Object.class));
    from.setName(annotation.getValue("name", String.class));
    from.setTitle(annotation.getValue("title", String.class));
    Double multipleOf = annotation.getValue("multipleOf", Double.class);
    if (multipleOf != null) {
        from.setMultipleOf(BigDecimal.valueOf(multipleOf));
    }
    String maximum = annotation.getValue("maximum", String.class);
    if (maximum != null && !maximum.isEmpty()) {
        from.setMaximum(new BigDecimal(maximum));
    }
    from.setExclusiveMaximum(annotation.getValue("exclusiveMaximum", Boolean.class));
    String minimum = annotation.getValue("minimum", String.class);
    if (minimum != null && !minimum.isEmpty()) {
        from.setMinimum(new BigDecimal(minimum));
    }
    from.setExclusiveMinimum(annotation.getValue("exclusiveMinimum", Boolean.class));
    from.setMaxLength(annotation.getValue("maxLength", Integer.class));
    from.setMinLength(annotation.getValue("minLength", Integer.class));
    from.setPattern(annotation.getValue("pattern", String.class));
    from.setMaxItems(annotation.getValue("maxItems", Integer.class));
    from.setMinItems(annotation.getValue("minItems", Integer.class));
    from.setUniqueItems(annotation.getValue("uniqueItems", Boolean.class));
    from.setMaxProperties(annotation.getValue("maxProperties", Integer.class));
    from.setMinProperties(annotation.getValue("minProperties", Integer.class));
    from.setRequired(annotation.getValue("requiredProperties", List.class));
    extractAnnotations(annotation, context, "properties", "name", SchemaImpl::createInstance, from::addProperty);
    for (Entry<String, Schema> property : from.getProperties().entrySet()) {
        final SchemaImpl propertySchema = (SchemaImpl) property.getValue();
        if (propertySchema.isRequired) {
            from.addRequired(property.getKey());
        }
    }
    from.setDescription(annotation.getValue("description", String.class));
    from.setFormat(annotation.getValue("format", String.class));
    from.setNullable(annotation.getValue("nullable", Boolean.class));
    from.setReadOnly(annotation.getValue("readOnly", Boolean.class));
    from.setWriteOnly(annotation.getValue("writeOnly", Boolean.class));
    from.setExample(annotation.getValue("example", Object.class));
    AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
    if (externalDocs != null) {
        from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
    }
    from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
    from.setEnumeration(annotation.getValue("enumeration", List.class));
    String discriminatorProperty = annotation.getValue("discriminatorProperty", String.class);
    List<AnnotationModel> discriminatorMapping = annotation.getValue("discriminatorMapping", List.class);
    if (discriminatorMapping != null && !discriminatorProperty.isEmpty()) {
        DiscriminatorImpl discriminator = new DiscriminatorImpl();
        discriminator.setPropertyName(discriminatorProperty);
        for (AnnotationModel mapping : discriminatorMapping) {
            String value = mapping.getValue("value", String.class);
            String schema = mapping.getValue("schema", String.class);
            discriminator.addMapping(value, ModelUtils.getSimpleName(schema));
        }
        from.setDiscriminator(discriminator);
    }
    String not = annotation.getValue("not", String.class);
    if (not != null) {
        Schema schema = from.getSchemaInstance(not, context);
        if (schema != null) {
            from.setNot(schema);
        }
    }
    List<String> anyOf = annotation.getValue("anyOf", List.class);
    if (anyOf != null) {
        mergeImmutableList(from.getAnyOf(), from.getSchemaInstances(anyOf, context), from::setAnyOf);
    }
    List<String> allOf = annotation.getValue("allOf", List.class);
    if (allOf != null) {
        mergeImmutableList(from.getAllOf(), from.getSchemaInstances(allOf, context), from::setAllOf);
    }
    List<String> oneOf = annotation.getValue("oneOf", List.class);
    if (oneOf != null) {
        mergeImmutableList(from.getOneOf(), from.getSchemaInstances(oneOf, context), from::setOneOf);
    }
    return from;
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) BigDecimal(java.math.BigDecimal) EnumModel(org.glassfish.hk2.classmodel.reflect.EnumModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ModelUtils.mergeImmutableList(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeImmutableList) ModelUtils.createList(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createList) List(java.util.List)

Example 2 with EnumModel

use of org.glassfish.hk2.classmodel.reflect.EnumModel in project Payara by payara.

the class ParameterImpl method createInstance.

public static Parameter createInstance(AnnotationModel annotation, ApiContext context) {
    ParameterImpl from = new ParameterImpl();
    from.setName(annotation.getValue("name", String.class));
    EnumModel inEnum = annotation.getValue("in", EnumModel.class);
    if (inEnum != null) {
        from.setIn(In.valueOf(inEnum.getValue()));
    }
    from.setDescription(annotation.getValue("description", String.class));
    from.setRequired(annotation.getValue("required", Boolean.class));
    from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
    from.setAllowEmptyValue(annotation.getValue("allowEmptyValue", Boolean.class));
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
    if (styleEnum != null) {
        from.setStyle(Style.valueOf(styleEnum.getValue()));
    }
    from.setExplode(annotation.getValue("explode", Boolean.class));
    from.setAllowReserved(annotation.getValue("allowReserved", Boolean.class));
    AnnotationModel schemaAnnotation = annotation.getValue("schema", AnnotationModel.class);
    if (schemaAnnotation != null) {
        Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
        if (hidden == null || !hidden) {
            from.setSchema(SchemaImpl.createInstance(schemaAnnotation, context));
        }
    }
    extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
    from.setExample(annotation.getValue("example", Object.class));
    final List<ContentImpl> contents = createList();
    extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
    for (ContentImpl content : contents) {
        content.getMediaTypes().forEach(from.content::addMediaType);
    }
    return from;
}
Also used : EnumModel(org.glassfish.hk2.classmodel.reflect.EnumModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 3 with EnumModel

use of org.glassfish.hk2.classmodel.reflect.EnumModel in project Payara by payara.

the class SecuritySchemeImpl method createInstance.

public static SecurityScheme createInstance(AnnotationModel annotation, ApiContext context) {
    SecuritySchemeImpl from = new SecuritySchemeImpl();
    EnumModel type = annotation.getValue("type", EnumModel.class);
    if (type != null) {
        from.setType(SecurityScheme.Type.valueOf(type.getValue()));
    }
    from.setDescription(annotation.getValue("description", String.class));
    from.setName(annotation.getValue("apiKeyName", String.class));
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    EnumModel in = annotation.getValue("in", EnumModel.class);
    if (in != null) {
        from.setIn(SecurityScheme.In.valueOf(in.getValue()));
    }
    from.setScheme(annotation.getValue("scheme", String.class));
    from.setBearerFormat(annotation.getValue("bearerFormat", String.class));
    AnnotationModel flowsAnnotation = annotation.getValue("flows", AnnotationModel.class);
    if (flowsAnnotation != null) {
        from.setFlows(OAuthFlowsImpl.createInstance(flowsAnnotation));
    }
    from.setOpenIdConnectUrl(annotation.getValue("openIdConnectUrl", String.class));
    return from;
}
Also used : EnumModel(org.glassfish.hk2.classmodel.reflect.EnumModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel)

Example 4 with EnumModel

use of org.glassfish.hk2.classmodel.reflect.EnumModel in project Payara by payara.

the class HeaderImpl method createInstance.

public static Header createInstance(AnnotationModel annotation, ApiContext context) {
    HeaderImpl from = new HeaderImpl();
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    from.setDescription(annotation.getValue("description", String.class));
    from.setRequired(annotation.getValue("required", Boolean.class));
    from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
    from.setAllowEmptyValue(annotation.getValue("allowEmptyValue", Boolean.class));
    EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
    if (styleEnum != null) {
        from.setStyle(Header.Style.valueOf(styleEnum.getValue()));
    }
    from.setExplode(annotation.getValue("explode", Boolean.class));
    AnnotationModel schemaAnnotation = annotation.getValue("schema", AnnotationModel.class);
    if (schemaAnnotation != null) {
        Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
        if (hidden == null || !hidden) {
            from.setSchema(SchemaImpl.createInstance(schemaAnnotation, context));
        }
    }
    extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
    from.setExample(annotation.getValue("example", Object.class));
    final List<ContentImpl> contents = createList();
    extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
    for (ContentImpl content : contents) {
        content.getMediaTypes().forEach(from.content::addMediaType);
    }
    return from;
}
Also used : EnumModel(org.glassfish.hk2.classmodel.reflect.EnumModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Aggregations

AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)4 EnumModel (org.glassfish.hk2.classmodel.reflect.EnumModel)4 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)2 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)2 ModelUtils.createList (fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createList)1 ModelUtils.mergeImmutableList (fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeImmutableList)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 Schema (org.eclipse.microprofile.openapi.models.media.Schema)1