input-output-hk / marlowe-cardano

Marlowe smart contract language Cardano implementation
Apache License 2.0
92 stars 44 forks source link

Marlowe Runtime REST API invalid #752

Closed nicolasLuduena closed 7 months ago

nicolasLuduena commented 11 months ago

Summary

I am trying to generate code automatically from the OpenAPI spec however it's not possible without having to tinker with it manually. The current spec is not a valid OpenAPI spec.

Steps to reproduce

Steps to reproduce the behavior:

  1. Run Marlowe Runtime REST API with cabal run marlowe-web-server -- --marlowe-runtime-host localhost -o -a.
  2. Go to http://localhost:8080/openapi.json.
  3. Download the output of that url in a file named openapi.json.
  4. Run npx @openapitools/openapi-generator-cli validate -i openapi.json. This is the output:
    
    Validating spec (openapi.json)
    Errors:
    - attribute components.schemas.MarloweState.items is not of type object
    - attribute components.schemas.Plutus.StakingCredential.items is missing
    - attribute components.schemas.Plutus.StakingCredential.items is not of type object
    - attribute components.schemas.MarloweState.items is missing
    Warnings: 
    - Unused model: WithdrawTxBodyEnvelope
    - Unused model: CreateTxBodyEnvelope

[error] Spec has 4 errors.



## Expected behavior
No errors here. Maybe a Github action that does this validation so the developers know if the latest commit has a valid OpenAPI spec.

## System info

- OS: Linux Mint 
- Version: 21 Cinnamon
- Plutus version or commit hash: 54c0074040adf5f2065b4f759b7883f45821053f
bjornkihlberg commented 11 months ago

Thanks for reporting this!

I'm currently working on applying these fixes in this ticket: https://github.com/input-output-hk/marlowe-ts-sdk/issues/100.

Maybe a Github action that does this validation so the developers know if the latest commit has a valid OpenAPI spec.

This is a good suggestion and something we want to do to prevent issues in the future.

nicolasLuduena commented 11 months ago

Thanks Bjorn! Btw if you are going to use 'oneOf', going for a change like this changes the generated code radically.

Here's an example of big change: Previously:

export type Contract = ContractOneOf | ContractOneOf1 | ContractOneOf2 | ContractOneOf3 | ContractOneOf4 | ContractOneOf5;

Now:

export type Contract = Assert | Close | If | Let | Pay | When;

The description for each schema is also transferred as comments & documentation!

bjornkihlberg commented 10 months ago

Hello again,

As I solved the issues earlier today, someone on my team noted that the schema satisfies OpenApi 3.1 so the old issue was dropped and a new one is created to solve this.

bjornkihlberg commented 10 months ago

We are now targeting OpenApi 3.1.0 in marlowe runtime on the main branch which means that heterogeneous arrays should be allowed for the items field in the schema. If there are any further issues, don't hesitate to notify us!

paluh commented 7 months ago

@nicolasLuduena can we close this issue?