Interface EmitterContext
public interface EmitterContext
What an emitter is given to write one contract's classes.
-
Method Summary
Modifier and TypeMethodDescriptiondefault List<ContractCase> contractCases(String location) The contract cases of an operation, in the order its generatedCASESlists them: success, not found, not acceptable, unsupported media type, then invalid requests.Records that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throwsUnsupportedOperationExceptionwith the reason and, where there is one, the remedy.model()The contract.names()The core classes, whose names an emitter's companions follow.parameterSchema(String location, String in, String name) The schema a path, query or header parameter of an operation must satisfy, as a self-contained JSON Schema 2020-12 document, made asrequestBodySchema(java.lang.String, java.lang.String)makes a body's.requestBodySchema(String location, String mediaType) The schema a request body of an operation must satisfy, as a self-contained JSON Schema 2020-12 document: every$refbundled into$defs, strict as the core's own notion of validity is whenstrictRequestsis on, and withformatasserted only for the formatsvalidateFormatsnames -- any other is written as the annotationx-format.default Optional<ResponseBody> responseBody(String location, String status) The body of a response an operation declares, in its first content type: the class that response's contract cases name, and the text its generatedrequiredBody()andfullBody()return, or why the core cannot build one.settings()How the project has asked for the classes to be generated.default voidWrites one file that belongs on no classpath -- a mapping file, part of an archive -- replacing any file already written at that path in this run.default voidWrites one text file that belongs on no classpath, UTF-8 encoded, aswriteFile(String, byte[])does.voidWrites one Java source file, replacing any file already written for that class in this run.voidwriteResource(String path, String content) Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads throughgetResourceAsStream, for instance.
-
Method Details
-
model
ContractModel model()The contract.- Returns:
- the model
-
settings
Settings settings()How the project has asked for the classes to be generated.- Returns:
- the settings
-
names
ClassNames names()The core classes, whose names an emitter's companions follow.- Returns:
- the class names
-
writeJava
Writes one Java source file, replacing any file already written for that class in this run.- Parameters:
packageName- the packagesimpleName- the class's simple namesource- the whole compilation unit
-
writeResource
Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads throughgetResourceAsStream, for instance.pathis/-separated and relative to the resource root, and may nest in directories, such as"META-INF/emitter/service.properties". It may not be absolute, and may not use empty,.or..segments.- Parameters:
path- the resource's path within the resource rootcontent- the resource's content, written UTF-8
-
writeFile
Writes one file that belongs on no classpath -- a mapping file, part of an archive -- replacing any file already written at that path in this run. The plugin packages these files; it never compiles them or puts them on a classpath.pathfollows the rules ofwriteResource(String, String):/-separated, relative, and without empty,.or..segments. Only an emitter whoseEmitter.produces(java.util.Map)includesOutput.FILESmay call it.- Parameters:
path- the file's path within the emitter's files directorycontent- the file's bytes- Throws:
UnsupportedOperationException- when this context has nowhere to write files: a generation run without a files directory
-
writeFile
Writes one text file that belongs on no classpath, UTF-8 encoded, aswriteFile(String, byte[])does.- Parameters:
path- the file's path within the emitter's files directorycontent- the file's text
-
degraded
Records that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throwsUnsupportedOperationExceptionwith the reason and, where there is one, the remedy. Every degraded method is reported at the end of generation.- Parameters:
className- the simple name of the class the method is inmethod- the method, as a reader would name it, such asbody(String)finding- the construct it cannot represent- Returns:
- a Java statement, without indentation
-
contractCases
The contract cases of an operation, in the order its generatedCASESlists them: success, not found, not acceptable, unsupported media type, then invalid requests. What an emitter that renders cases shapes its code by. The core derives them before any other emitter runs.- Parameters:
location- the JSON pointer of the operation, such as/paths/~1v1~1users/get- Returns:
- the cases; empty when the operation has none, or there is no such operation
-
responseBody
The body of a response an operation declares, in its first content type: the class that response's contract cases name, and the text its generatedrequiredBody()andfullBody()return, or why the core cannot build one. An emitter that writes a response as a file, which cannot call those methods, takes its text from here.- Parameters:
location- the JSON pointer of the operation, such as/paths/~1v1~1users/getstatus- the response's key as the contract declares it, such as200- Returns:
- the body; empty when the operation declares no such response, or it has no content or no generated body class
-
requestBodySchema
The schema a request body of an operation must satisfy, as a self-contained JSON Schema 2020-12 document: every$refbundled into$defs, strict as the core's own notion of validity is whenstrictRequestsis on, and withformatasserted only for the formatsvalidateFormatsnames -- any other is written as the annotationx-format. It is exactly the schema the core generates valid bodies for and derives invalid ones against.- Parameters:
location- the JSON pointer of the operationmediaType- the request body's media type, as the operation declares it- Returns:
- the schema's JSON text; empty when the operation declares no such body or its schema
-
parameterSchema
The schema a path, query or header parameter of an operation must satisfy, as a self-contained JSON Schema 2020-12 document, made asrequestBodySchema(java.lang.String, java.lang.String)makes a body's. A value travels as a string: the schema is that of the value it stands for, so a stub matching a path segment by itspatternreads it here.- Parameters:
location- the JSON pointer of the operationin- where the parameter is:path,queryorheadername- the parameter's name- Returns:
- the schema's JSON text; empty when the operation declares no such parameter or its schema
-