7mind / idealingua-v1

IdeaLingua RPC for Scala, TypeScript, C#, Go
https://izumi.7mind.io/idealingua
BSD 2-Clause "Simplified" License
20 stars 4 forks source link

API descriptor generator #52

Open pshirshov opened 6 years ago

pshirshov commented 6 years ago

We may implement a tool converting a JSON into a set of model drafts.

This API call:

{
  "personalizations": [
    {
      "to": [
        {
          "email": "john.doe@example.com",
          "name": "John Doe"
        }
      ],
      "subject": "Hello, World!"
    }
  ],
  "from": {
    "email": "sam.smith@example.com",
    "name": "Sam Smith"
  },
  "reply_to": {
    "email": "sam.smith@example.com",
    "name": "Sam Smith"
  }
}

may be translated into

data emailuser {
   email: str
   name: str
}

data emailData {
   to: list[emailuser]
   subject: str
}

data {
   personalizations: list[emailData]
   from: emailUser
   reply_to: emailUser
}

This may allow us to interoperate with simple REST data providers.

Also we may convert swagger and other popular formats into our models. Kinda related: 7mind/idealingua-v1#19

ratoshniuk commented 6 years ago

@pshirshov How get should deal with follow input?

"from": {
    "email": "sam.smith@example.com",
    "name": "Sam Smith"
  },
  "reply_to": {
    "email": "sam.smith@example.com",
    "name": "Sam Smith"
    "extra_field" : "foo"    // new field!
  }

Either:

// One for both inputs
data emailUser {
    email : str
    name : str
    extraField : opt[str]
}

or

data emailUser {
    email : str
    name : str
}

data emailUserWithExtra {
    email : str
    name : str
    extraField : str
}
pshirshov commented 6 years ago

I guess second one. From what I can see first one requires a complex and fragile heuristic.