apigear-io / cli

The ApiGear client as go project
https://apigear.io
MIT License
1 stars 2 forks source link

interface references #129

Closed jryannel closed 2 months ago

jryannel commented 6 months ago

Allow interfaces to be used in the API surface, they should already be usable but it is not sure if all templates support them.

Here is an example:

interface Radio { ... }
interface Registry {
  get(name: string): Radio
}

To make this work we need to ensure that all filters in all technologies do return interfaces.

We need also decide if interfaces in structs are allowed?

jryannel commented 5 months ago

You can add now interfaces as part of your references:

IDL

module demo 1.0

interface Common {
    value3: int
}

interface Counter {
    getCommon(): Common
}

YAML

name: demo
version: "1.0"

interfaces:
  - name: Common
  - name: Counter
    operations:
      - name: getCommon
        return:
          type: Common

Code

Will result into code like


package demo

// Data Structures
type Common interface {
    // Methods

}
type Counter interface {
    // Methods
    GetCommon() Common
}

Filters

In the filters only the interface case needs to be handled:

func ToReturnString(prefix string, schema *model.Schema) (string, error) {
  ...
    case model.TypeInterface:
        text = fmt.Sprintf("%s%s", prefix, schema.Type)
  ...
}
jryannel commented 2 months ago

We will not implement this. We expect interfaces can not be used a references.