[
https://issues.apache.org/jira/browse/THRIFT-3316?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Motiejus Jakštys updated THRIFT-3316:
-------------------------------------
Description:
Not sure if it's a bug, or I am missing something, or compiler does not allow
to create const structs referring to other structs. E.g.:
{code}
struct Book {
1: i32 id
}
struct Author {
1: Book book
}
const Book bookEx1 = { // example instance of Book
'id': 1
}
const Author AuthorEx1 = { // example instance of Author
//'book': { 'id': 1 } // This is a copy from above, but works well
'book': BookEx1 // this doesn't work, see below
}
{code}
When compiling, it gives the following error:
{code}
$ thrift -v -gen js:ts model.thrift
Scanning model.thrift for includes
Parsing model.thrift for types
[FAILURE:model.thrift:17] type error: const "AuthorEx1.book" was declared as
struct/xception
{code}
Problem: I want to refer to other defined const structs by already defined
structs from before (e.g. bookEx1) instead of flattening the values. Am I
missing something, or is this unsupported, or just a bug?
Use case: for every model, I am creating mock `const` values which the services
can re-use in their tests.
I asked this on stackoverflow too:
http://stackoverflow.com/questions/32424858/writing-thrift-schemas-non-flattened-struct-constants-makes-me-repetitive
was:
Compiler does not allow to create const structs referring to other structs.
E.g.:
{code}
struct Book {
1: i32 id
}
struct Author {
1: Book book
}
const Book bookEx1 = { // example instance of Book
'id': 1
}
const Author AuthorEx1 = { // example instance of Author
//'book': { 'id': 1 } // This is a copy from above, but works well
'book': BookEx1 // this doesn't work, see below
}
{code}
When compiling, it gives the following error:
{code}
$ thrift -v -gen js:ts model.thrift
Scanning model.thrift for includes
Parsing model.thrift for types
[FAILURE:model.thrift:17] type error: const "AuthorEx1.book" was declared as
struct/xception
{code}
Problem: I want to refer to other defined const structs by already defined
structs from before (e.g. bookEx1) instead of flattening the values. Am I
missing something, or is this unsupported?
Use case: for every model, I am creating mock `const` values which the services
can re-use in their tests.
I asked this on stackoverflow too:
http://stackoverflow.com/questions/32424858/writing-thrift-schemas-non-flattened-struct-constants-makes-me-repetitive
Summary: Non-flattened struct consts are not allowed (was: Writing
non-flattened struct consts is not allowed)
> Non-flattened struct consts are not allowed
> -------------------------------------------
>
> Key: THRIFT-3316
> URL: https://issues.apache.org/jira/browse/THRIFT-3316
> Project: Thrift
> Issue Type: New Feature
> Affects Versions: 0.9.2
> Reporter: Motiejus Jakštys
>
> Not sure if it's a bug, or I am missing something, or compiler does not allow
> to create const structs referring to other structs. E.g.:
> {code}
> struct Book {
> 1: i32 id
> }
> struct Author {
> 1: Book book
> }
> const Book bookEx1 = { // example instance of Book
> 'id': 1
> }
> const Author AuthorEx1 = { // example instance of Author
> //'book': { 'id': 1 } // This is a copy from above, but works well
> 'book': BookEx1 // this doesn't work, see below
> }
> {code}
> When compiling, it gives the following error:
> {code}
> $ thrift -v -gen js:ts model.thrift
> Scanning model.thrift for includes
> Parsing model.thrift for types
> [FAILURE:model.thrift:17] type error: const "AuthorEx1.book" was declared as
> struct/xception
> {code}
> Problem: I want to refer to other defined const structs by already defined
> structs from before (e.g. bookEx1) instead of flattening the values. Am I
> missing something, or is this unsupported, or just a bug?
> Use case: for every model, I am creating mock `const` values which the
> services can re-use in their tests.
> I asked this on stackoverflow too:
> http://stackoverflow.com/questions/32424858/writing-thrift-schemas-non-flattened-struct-constants-makes-me-repetitive
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)