Skip to content

Instantly share code, notes, and snippets.

@tadelesh
Last active June 7, 2024 08:00
Show Gist options
  • Save tadelesh/028a87a9fa6a22cbfc76bbda7284bafe to your computer and use it in GitHub Desktop.
Save tadelesh/028a87a9fa6a22cbfc76bbda7284bafe to your computer and use it in GitHub Desktop.

Request

With exact body definition

model Foo {}
op foo(@query q: string, @header h: string, @body body: Foo): void;

Service method parameters:

  • q: string
  • h: string
  • body: Foo {}

Service operation:

  • parameters
    • q: string
    • h: string
  • bodyParam: Foo {}

Mapping:

  • q -> q
  • h -> h
  • bodyParam -> body

Generated models:

  • Foo

With auto body resolution

model Inner {
  @header
  h: string;
  prop: string;
}
op foo(@query q: string, outer: string, inner: Inner): void;

Service method parameters:

  • q: string
  • outer: string
  • inner: Inner {h: string, prop: string}

Service operation:

  • parameters
    • q: string
    • h: string
  • bodyParam: FooRequest {outer: string, inner: Inner {h: string, prop: string}}

Mapping:

  • q -> q
  • bodyParam.outer -> outer
  • bodyParam.inner -> inner
  • h -> inner.h

Generated models:

  • Inner
  • FooRequest

With body resolution from specific property

model Inner {
  @header
  h: string;
  prop: string;
}
op foo(@bodyRoot body: {@query q: string, outer: string, inner: Inner}): void;

Service method parameters:

  • body: FooRequest {q: string, outer: string, inner: Inner {h: string, prop: string}}

Service operation:

  • parameters
    • q: string
    • h: string
  • bodyParam: FooRequest {q: string, outer: string, inner: Inner {h: string, prop: string}}

Mapping:

  • q -> body.q
  • h -> body.inner.h
  • bodyParam -> body

Generated models:

  • FooRequest
  • Inner

With spread and auto body resolution

model Wrapper {
  @query
  q: string;
  outer: string;
  inner: Foo;
}
model Foo {
  @header
  h: string;
  prop: string;
}
op foo(...Wrapper): void;

Service method parameters:

  • q: string
  • outer: string
  • inner: Inner {h: string, prop: string}

Service operation:

  • parameters
    • q: string
    • h: string
  • bodyParam: FooRequest {outer: string, inner: Inner {h: string, prop: string}}

Mapping:

  • q -> q
  • bodyParam.outer -> outer
  • bodyParam.inner -> inner
  • h -> inner.h

Generated models:

  • Inner
  • FooRequest

Response

With exact body definition

model Foo {}
op foo(): {@header h: string, @body body: Foo};

Service method response:

  • FooResponse {h: string, body: Foo{}}

Service operation response:

  • headers
    • h: string
  • body: Foo {}

Mapping:

  • h -> FooResponse.h
  • body -> FooResponse.body

Generated models:

  • FooResponse
  • Foo

With auto body resolution

model Inner {
  @header
  h: string;
  prop: string;
}
op foo(): {@header oh: string, outer: string, inner: Inner};

Service method response:

  • FooReturn {oh: string, outer: string, inner: Inner {h: string, prop: string}}

Service operation response:

  • headers
    • oh: string
    • h: string
  • body: FooResponse {outer: string, inner: Inner {h: string, prop: string}}

Mapping:

  • oh -> FooResponseSource.oh
  • h -> FooResponseSource.inner.h
  • body.outer -> FooResponseSource.outer
  • body.inner -> FooResponseSource.inner

Generated models:

  • Inner
  • FooResponse
  • FooReturn

With body resolution from specific property

model Inner {
  @header
  h: string;
  prop: string;
}
op foo(): {@bodyRoot body: {@header oh: string, outer: string, inner: Inner}};

Service method response:

  • FooReturn {body: FooResponse {oh: string, outer: string, inner: Inner {h: string, prop: string}}

Service operation response:

  • headers
    • oh: string
    • h: string
  • body: FooResponse {oh: string, outer: string, inner: Inner {h: string, prop: string}}

Mapping:

  • oh -> FooResponse.body.oh
  • h -> FooResponse.body.inner.h
  • body-> FooResponse

Generated models:

  • Inner
  • FooResponse
  • FooReturn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment