Name: ContractExamples

Extends: CommonParent

Properties:
  sampleClass:
    Contract: $.class(SampleClass1)

  ordinaryProperty:
    Contract: $.string()

  templateProperty:
    Contract: $.template(TemplateTestChild, excludeProperties => [bar])

Methods:
  testStringContract:
    Arguments:
      arg:
        Contract: $.string()
    Body:
      Return: $arg

  testIntContract:
    Arguments:
      arg:
        Contract: $.int()
    Body:
      Return: $arg

  testBoolContract:
    Arguments:
      arg:
        Contract: $.bool()
    Body:
      Return: $arg

  testClassContract:
    Arguments:
      arg:
        Contract: $.class(SampleClass2)
    Body:
      Return: $arg

  testTemplateContract:
    Arguments:
      arg:
        Contract: $.template(CreatedClass2)
    Body:
      Return: $arg

  testTemplateContractExcludePropertyFromMpl:
    Body:
      - $model:
          :CreatedClass2:
            property1: qwerty
            property2: 'not integer'
      - Return: $.testTemplateContractExcludeProperty($model)

  testTemplateContractExcludeProperty:
    Arguments:
      arg:
        Contract: $.template(CreatedClass2, excludeProperties => [property2])
    Body:
      Return: $arg

  testClassFromIdContract:
    Arguments:
      arg:
        Contract: $.class(SampleClass1)
    Body:
      Return: $arg

  testCheckContract:
    Arguments:
      - arg1:
          Contract: $.class(SampleClass2).check($.class2Property = qwerty)
      - arg2:
          Contract: $.int().check($ > 10)

  testOwnedContract:
    Arguments:
      - arg1:
          Contract: $.class(SampleClass1).owned()
      - arg2:
          Contract: $.class(SampleClass2).owned()

  testNotOwnedContract:
    Arguments:
      - arg1:
          Contract: $.class(SampleClass1).notOwned()
      - arg2:
          Contract: $.class(SampleClass2).notOwned()

  testScalarContract:
    Arguments:
      - arg1:
          Contract: 'fixed'
      - arg2:
          Contract: 456
      - arg3:
          Contract: true
    Body:
      Return: $arg1

  testListContract:
    Arguments:
      - arg:
          Contract: [$.int()]
    Body:
      Return: $arg

  testListWithMinLengthContract:
    Arguments:
      - arg:
          Contract: [$.int(), 3]
    Body:
      Return: $arg

  testListWithMinMaxLengthContract:
    Arguments:
      - arg:
          Contract: [$.int(), 2, 4]
    Body:
      Return: $arg

  testDictContract:
    Arguments:
      - arg:
          Contract:
            A: $.string()
            B: $.int()
    Body:
      Return: $arg

  testDictExprContract:
    Arguments:
      - arg:
          Contract:
            $.int(): $.string()
            B: $.int()
    Body:
      Return: $arg

  testDictMultiExprContract:
    Arguments:
      - arg:
          Contract:
            $.int(): $.string()
            $.string(): $.int()
    Body:
      Return: $arg

  testNotNullContract:
    Arguments:
      - arg:
          Contract: $.notNull()
    Body:
      Return: $arg

  testDefault:
    Arguments:
      - arg:
          Contract: $.string()
          Default: DEFAULT
    Body:
      Return: $arg

  testDefaultExpression:
    Arguments:
      - arg:
          Contract: $.string()
          Default: $.ordinaryProperty
    Body:
      Return: $arg

  testActionMeta:
    Scope: Public
    Meta:
      - io.murano.metadata.Title:
          text: "Title of the method"
      - io.murano.metadata.Description:
          text: "Description of the method"
      - io.murano.metadata.HelpText:
          text: "HelpText of the method"

  notAction:
    Scope: Session

  testAction:
    Scope: Public

---

Name: TestedTarget

Properties:
  prop:
    Contract:
      - $.string()
Methods:
  foo:
    Arguments:
      - contracted:
          Contract:
            - $.string()
    Body:
      - Return: $contracted[2]

  wildList:
    Arguments:
      - contracted:
          Contract:
            - $
    Body:
      - Return: $contracted[1][2]

  wildContract:
    Arguments:
      - untyped:
          Contract: $
    Body:
      - Return: $untyped[1]

  typedList:
    Arguments:
      - contracted:
          Contract:
            - [$.string()]
    Body:
      - Return: $contracted[1][2]

  dictArgs:
    Arguments:
      - arg:
          Contract: {$.string(): [$.int()]}
    Body:
      - Return: $arg.get('a')[1]

---

Name: TestIteratorsTransform
Methods:
  testProperties:
    Body:
      - $.target: new(TestedTarget, $this, prop => ['1', '2', '3'].where($))
      - Return: $.target.prop[2]
  testArgs:
    Body:
      - $.target: new(TestedTarget, $this)
      - Return: $.target.foo(['1', '2', '3'].where($))
  testUntypedArgs:
    Body:
      - $.target: new(TestedTarget, $this)
      - Return: $.target.wildContract(['1', '2', '3'].where($))
  testNotTypedListArgs:
    Body:
      - $.target: new(TestedTarget, $this)
      - Return: $.target.wildList([['1', '2', '3'].where($), ['4', '5', '6'].where($)].where($))
  testTypedList:
    Body:
      - $.target: new(TestedTarget, $this)
      - Return: $.target.typedList([['1', '2', '3'].where($), ['4', '5', '6'].where($)].where($))
  testListDict:
    Body:
      - $.target: new(TestedTarget, $this)
      - Return: $.target.dictArgs({'a' => [1, 2, 4].where($)})

---

Name: TemplateTestChild

Properties:
  bar:
    Contract: $.int().notNull()

---

Name: TemplatePropertyClass
Properties:
  owned:
    Contract: $.class(Node)
  template:
    Contract: $.template(Node)

Methods:
  testTemplateWithExternallyOwnedObject:
    Body:
     - Return: new($.template).nodes.select(id($))
