redskap / swagger-brake

Swagger contract checker for breaking API changes
Apache License 2.0
57 stars 16 forks source link

Schema class attributeRequiredMap.get(attrToSearchFor); returning null #65

Closed zsiryani closed 1 year ago

zsiryani commented 2 years ago

Hello, I have a case where attributeRequiredMap.get(attrToSearchFor); is returning null in the Boolean isRequired like the following Image

image

I was wondering if the isRequired can be converted into a primitive boolean in order not to have NPE, the following is the content of the map

image

Also current attrToSearchFor value is urn:scim:schemas:extension:workspace:1 the closest value in the map is urn:scim:schemas:extension:workspace:1.0 I suspect that is this something related to the construction of attrToSearchFor using the stringJoiner.

Thank you

galovics commented 2 years ago

Hi @zaidsir, Thanks for reporting these issues. I'll take a look when I have the time unless you have a PR prepared. ;-)

lavanya2290 commented 2 years ago

The same works in 2.2.0 verions It handles NPE. Like making use of Optional.ofNullable. class name: Schema

public Set<String> getRequiredAttributeNames() {
        Collection<SchemaAttribute> schemaAttrs = schemaAttributes;
        if (CollectionUtils.isEmpty(schemaAttrs)) {
            schemaAttrs = Optional.ofNullable(schema).map(Schema::getSchemaAttributes).orElse(Collections.emptySet());
        }
        return internalGetAttributeData(schemaAttrs, "", SchemaAttribute::isRequired)
            .stream()
            .filter(p -> BooleanUtils.isTrue(p.getRight()))
            .map(Pair::getLeft)
            .collect(toSet());
    }

versus new method in 2.3.0 causes issues i.e. NPE. Example we can have a variable annotated with public static final String SCHEMA = "urn:abc:def:abc:abc:1.0";

zsiryani commented 2 years ago

Hello @galovics, a simple pull request created. Please review it

galovics commented 1 year ago

Just for reference, the PR is here: https://github.com/redskap/swagger-brake/pull/66

galovics commented 1 year ago

@zaidsir the other issue, with the complex dotted attribute name is fixed with this PR: https://github.com/redskap/swagger-brake/pull/84