commercetools / commercetools/scraml

Enhance AdditionalProperties support

Open
#41 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
RAML
Stars
10
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Current support for [AdditionalProperties](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#additional-properties) unconditionally adds an `additionalProperty` to generated case classes (depending on the applicable `FieldMatchPolicy`). While this works, three enhancements to this functionality would improve developer experience.

**Support type declaration**

If an additional properties has a `type` declaration, it should be used instead of the default "any type". For example (based on the RAML specification):

```
#%RAML 1.0
title: My API With Types
types:
Person:
properties:
name:
required: true
type: string
age:
required: false
type: number
/^note\d+$/: # restrict any properties whose keys start with "note"
# followed by a string of one or more digits
type: string
```

In this case, `Person` should have an `additionalProperties` which has `String` as its value type. If more than one property regular expression exists having `type` declarations which are not type compatible, current behaviour could be the fallback.

**Code generation when no named properties exist**

This is a special case refining what type of Scala code is generated when a RAML type only has property regular expressions. For example (again, based on the example in the RAML specification):

```
#%RAML 1.0
title: My API With Types
types:
Person:
properties:
/^note\d+$/: # restrict any properties whose keys start with "note"
# followed by a string of one or more digits
type: string
```

Currently, a Scala case class will be generated similar to:

```
final case class Person()(val additionalProperties: Option[Person.AdditionalProperties] = None)
```

In this situation, `scraml` could instead generate code similar to:

```
final case class Person(properties: Person.AdditionalProperties = Person.AdditionalProperties.empty)
```

**AdditionalProperties manipulation methods**

Consider adding methods to the generated `Person` type (shown above) which assist in manipulating either the generated `properties` or `additionalProperties` may enhance developer experience.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.