Skip to content

allow for user-provided naming of endpoints #65

@costasvassilakis

Description

@costasvassilakis

The current implementation assigns randomly generated names to endpoints, which is not convenient for programmers - using intuitive names would be best.

An easy way round this is to allow for the first line of the query to contain a specification of the form

#+id: apiID

and then the createSpecification extracts and uses the id, if present.

All that is needed is to modify basil/src/main/java/uk/ac/open/kmi/basil/core/ApiManagerImpl.java as follows:

  1. include the following lines in public class ApiManagerImpl implements ApiManager:
        final String IdSpecPrefix = "#+id:";
        final int MaxIdLength = 60;
  1. modify the public String createSpecification(String username, String endpoint, String body) method as follows:
// MODIFICATION START: extract first line to test if contains an id spec
                if (body.startsWith(IdSpecPrefix)) {
                        //String[] result = body.split("\r\n|\r|\n", 2);
                        String[] result = java.util.regex.Pattern.compile("\r\n|\r|\n").split(body, 2);

                        body = result[1];
                        //String[] idparts = result[0].split(":", 2);
                        String[] idparts = java.util.regex.Pattern.compile(":").split(result[0], 2);
                        id = idparts[1].trim();
                        if (id.length() == 0) {
                                throw new SpecificationParsingException("Specified id is empty");
                        }
                        if (id.length() > MaxIdLength) {
                                throw new SpecificationParsingException("Specified id length (" + id.length() + ") exceeds the maximum of " + MaxIdLength);
                        }
                        if (! javax.lang.model.SourceVersion.isIdentifier(id)) {
                                throw new SpecificationParsingException("Specified id (" + id + ") is not a valid identifier");
                        }
                }
// MODIFICATION END
                if (body.equals("")) {
                        throw new SpecificationParsingException("Body cannot be empty");
                }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions