RepreZen / KaiZen-OpenAPI-Editor

Eclipse Editor for the Swagger-OpenAPI Description Language
Eclipse Public License 1.0
115 stars 12 forks source link

`_type_` as context assist proposal for context schema #411

Open tfesenko opened 6 years ago

tfesenko commented 6 years ago

Extracted from https://github.com/RepreZen/KaiZen-OpenAPI-Editor/pull/402#pullrequestreview-67663598

I noted that there is a content assist proposal _key_ present in responses > content > schema. Not sure why it is there. screen shot 2017-10-06 at 15 19 39

Test added in 0baa0ab

It happens because

  1. We are combining all subtype contest assist proposals for a complex type, see com.reprezen.swagedit.core.assist.JsonProposalProvider.createComplextTypeProposals(ComplexTypeDefinition, AbstractNode, String):
        for (TypeDefinition definition : type.getComplexTypes()) {
            proposals.addAll(getProposals(definition, node, prefix));
        }
  2. For each subtype, we call JsonProposalProvider.createObjectProposals(ObjectTypeDefinition, AbstractNode, String), which creates the _type_ proposal when there are no other proposals:
        if (proposals.isEmpty()) {
            proposals.add(new Proposal("_key_" + ":", "_key_", null, null));
        }

The given context is defined by a complex schemaOrReference type. reference is one of its subtypes, and it does not have other keyword-based context assist proposals, so we are adding the _key_ proposal.

Solutions

  1. We can add the default _key_ proposal only when the aggregate result is empty.
  2. Or, we can investigate if we need the _key_ at all and possibly remove it. _key_ was introduced before we had code-assist for the elements described with additionalProperties and was mostly added to cover the additionalProperties cases.