Adding JSON object as annotation value - Forum - OpenEdge Development - Progress Community

Adding JSON object as annotation value

 Forum

Adding JSON object as annotation value

This question is not answered

We're currently developing our new web applications in a PAS environment.

To allow a more independent development in front-end an back-end, I'd like to use a temp-table as a way to pass parameters back and forth (ttParameter), without having to adapt the interface too much when new parameters are added or old parameters are deprecated. An additional advantage is that this allows a more generic treatment of the parameters in the back-end and the front-end.

Anyway, this all works, great, yet now the front-end lacks the ability to see which parameters are expected in the call or to be expected as a result. The catalog might describe the schema of ttParameter, but it gives no information on which records it can contain.

That's why we'd like to use custom method annotations. When added to the catalog, these can then be interpreted by the front-end. Here's the information we'd like to pass to the front-end:

For each parameter:

  • The name (Code)
  • The input-type (input, output or both)
  • The variable type (string, integer...)
  • Whether it's optional or required

To avoid having to add too many annotations, this would be a clear format which can easily be interpreted by the javascript or C# front-end:

@openapi.openedge.method.property (name="ttParaDefDirector", value='{Code: "Company", InputOutput: "INPUT", Type: "string", Required: false}').
@openapi.openedge.method.property (name="ttParaDefMovieTitle", value='{Code: "MovieTitle", InputOutput: "INPUT", Type: "string", Required: false}').
@openapi.openedge.method.property (name="ttParaDefActor", value='{Code: "Actor", InputOutput: "INPUT", Type: "string", Required: false}').

The OpenEdge documentation on annotations clearly states that any string value can be used for an annotation: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/pdsoe%2Fabl-annotation-syntax.html%23wwID0E1BK3

But sadly the "{...}" is seen as an include of a file, so you get errors when trying to enter this value.

The only proper way to resolve this should be clear; we escape the "{" character. And in the PDS procedure editor that even works; no more errors. This annotation is accepted:

@openapi.openedge.method.property (name="ttParaDefDirector", value='~{Code: "Company", InputOutput: "INPUT", Type: "string", Required: false}').

Now that this character is escaped, I would expect that the result in the catalog would be the same string, but without the "~". Too bad; the escape character is copied to the catalog, rendering the json object broken.

Is there a better way to include a JSON object as a value in an annotation?

And, to take it a step farther; would there be a way to shorten the notation, i.e. by creating an include with preprocessors, like;

@openapi.openedge.method.property (name="ttParaDef{&PARAMCODE}", value='~{Code: "{&PARAMCODE}", Input: "{&INPUT}", Type: "{&JSTYPE}", Required: {&REQUIRED}}').

I tried this, but the preprocessors are not taken into account when the catalog is generated, the string is just copied with the preprocessors as strings.

I know that there are other ways to pass data through annotations, but JSON is so widely used that there should be a way to use it here too, I think...

All Replies
  • What happens if you put this '{Code: "MovieTitle", InputOutput: "INPUT", Type: "string", Required: false}'

    into a scoped-define like so:

    &SCOPED-DEFINE MovieTitle ~{Code: "MovieTitle", InputOutput: "INPUT", Type: "string", Required: false~}

    @openapi.openedge.method.property (name="ttParaDefMovieTitle", value='{&MovieTitle}').

    I'm thinking this may get the parser to strip the ~ from the define and then put the result in your annotation instead of getting a literal in your catalog.

  • It does interprete the preprocessor, apparently, and the "~" is removed, but it just gives the same error: Code not found (file not found).